SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[QMUH_EFATISL]'))
EXEC dbo.sp_executesql @statement = N'ALTER VIEW [dbo].[QMUH_EFATISL] as  SELECT *,   
 CAST(CASE WHEN TEV_CARPAN = 1 AND TEV_BOLEN = 1 THEN 0.00 ELSE ((SATIR.SATIRKDVTUTAR * TEV_CARPAN) / TEV_BOLEN) END AS FLOAT) TEV_TUTAR,
 CAST(CASE WHEN TEV_CARPAN = 1 AND TEV_BOLEN = 1 THEN 0.00 ELSE (((100.00 * TEV_CARPAN) / TEV_BOLEN)) END AS FLOAT) TEV_ORAN
 FROM (
 SELECT  FATISL.FATID,FATISL.FATISLID AS SATIRNO, ISNULL(FATISL.FADET, 1.00) AS SATIRADET,
         FATISL.FBFIYAT AS SATIRBFIYAT,
         FATISL.KDV AS SATIRKDVORAN, CASE WHEN (ISNULL(STOK.STOKID,0) < 0) THEN FATISL.ACIKLAMA ELSE STOK.ADI END  AS SATIRACIKLAMA,
         ISNULL(FI.SATIRIND,0)  SATIRIND,
		 ISNULL(FI.SATIRIND2,0) SATIRIND2, ISNULL(FBIRIM,''Adet'') as FBIRIM,
         FATISL.NSATISKDV AS SATIRKDVTUTAR, FATISL.KDV2,
         FATISL.SATIRNTUTART AS ARATOPLAM,
         FI.KDVACIKLAMA,FI.KDVSIZLIKKODU,FI.TEVKANUNKODU,FI.TEVKANUNACIKLAMA,
         CAST(CASE WHEN CHARINDEX(''/'',ISNULL(FATISL.TEVORAN,''''),1) < 1 THEN 1 ELSE LEFT(FATISL.TEVORAN,CHARINDEX(''/'', FATISL.TEVORAN,1)-1) END AS FLOAT) TEV_CARPAN,
         CAST(CASE WHEN CHARINDEX(''/'',ISNULL(FATISL.TEVORAN,''''),1) < 1 THEN 1 ELSE RIGHT(FATISL.TEVORAN,LEN(FATISL.TEVORAN) - CHARINDEX(''/'', FATISL.TEVORAN,1)) END AS FLOAT) TEV_BOLEN 
 FROM VWFATURAISL FATISL
 INNER JOIN FATISL FI ON FI.FATISLID = FATISL.FATISLID
 LEFT JOIN STOK ON FATISL.STOKID=STOK.STOKID
 ) SATIR
 ' 
GO