IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QMUH_SATINALMA_ANLASMAISL]') AND OBJECTPROPERTY(id,N'IsVIew') = 1)
BEGIN
    INSERT INTO SCRIPT_BACKUPS (SCRIPTNAME,SCRIPT,SCRIPTDATE) SELECT 'QMUH_SATINALMA_ANLASMAISL' SCRIPTNAME,OBJECT_DEFINITION(OBJECT_ID('QMUH_SATINALMA_ANLASMAISL')) AS SCRIPT,GETDATE() AS SCRIPTDATE
    DROP VIEW QMUH_SATINALMA_ANLASMAISL
END
GO

create VIEW [dbo].[QMUH_SATINALMA_ANLASMAISL] AS 
SELECT     MUH_SATINALMA_ANLASMAISL.ANLASMAISLID, MUH_SATINALMA_ANLASMAISL.ANLASMAID, MUH_SATINALMA_ANLASMAISL.STOKID, 
                      MUH_SATINALMA_ANLASMAISL.BIRIM, MUH_SATINALMA_ANLASMAISL.KOTA, MUH_SATINALMA_ANLASMAISL.MARKAID, 
                      MUH_SATINALMA_ANLASMAISL.MARKANOTE AS MARKA, MUH_SATINALMA_ANLASMAISL.FIYAT, MUH_SATINALMA_ANLASMAISL.DOVIZ, STOK.KODU, STOK.ADI, 
                      MUH_SATINALMA_ANLASMA.CARIID, MUH_SATINALMA_ANLASMA.BTARIH, MUH_SATINALMA_ANLASMA.STARIH, MUH_SATINALMA_ANLASMA.AKTIF, 
                      MUH_SATINALMA_ANLASMA.ANLASMANO, MUH_SATINALMA_ANLASMA.CARIID AS FIRMAID, ETS_CARI.KODU AS FIRMAKODU, 
                      ETS_CARI.UNVANI AS FIRMAADI, MUH_SATINALMA_ANLASMA.ALTCARIID AS ALTFIRMAID, CAST(NULL AS NVARCHAR(50)) AS ALTFIRMAKODU, 
                      CAST(NULL AS NVARCHAR(100)) AS ALTFIRMAADI, MUH_SATINALMA_ANLASMAISL.ISKONTOORAN, MUH_SATINALMA_ANLASMAISL.ISKONTOORAN2, 
                      MUH_SATINALMA_ANLASMAISL.ISKONTOORAN3, 
                      MUH_SATINALMA_ANLASMAISL.FIYAT - ((MUH_SATINALMA_ANLASMAISL.FIYAT * ISNULL(MUH_SATINALMA_ANLASMAISL.ISKONTOORAN, 0) 
                      / 100 + MUH_SATINALMA_ANLASMAISL.FIYAT * ISNULL(MUH_SATINALMA_ANLASMAISL.ISKONTOORAN2, 0) / 100) 
                      + MUH_SATINALMA_ANLASMAISL.FIYAT * ISNULL(MUH_SATINALMA_ANLASMAISL.ISKONTOORAN3, 0) / 100) AS NETFIYAT,
					  MUH_SATINALMA_ANLASMA.ONAYLANDI,MUH_SATINALMA_ANLASMA.ONAYKULLANICI,MUH_SATINALMA_ANLASMA.ONAYZAMANI
FROM         MUH_SATINALMA_ANLASMA INNER JOIN
                      MUH_SATINALMA_ANLASMAISL ON MUH_SATINALMA_ANLASMA.ANLASMAID = MUH_SATINALMA_ANLASMAISL.ANLASMAID INNER JOIN
                      STOK ON MUH_SATINALMA_ANLASMAISL.STOKID = STOK.STOKID INNER JOIN
                      ETS_CARI ON MUH_SATINALMA_ANLASMA.CARIID = ETS_CARI.CARIID 
WHERE     (ISNULL(MUH_SATINALMA_ANLASMA.AKTIF, 1) = 1) AND (ISNULL(MUH_SATINALMA_ANLASMAISL.BEDELSIZ, 0) = 0)
GO

