DECLARE @FATID INT = (SELECT MIN(FATID)-1 FROM FATURA WHERE KYTARIH>(CONVERT(VARCHAR,YEAR(DATEADD(MONTH,-2,GETDATE()))) + '-' + RIGHT('0'+CONVERT(VARCHAR,MONTH(DATEADD(MONTH,-2,GETDATE()))),2) + '-01'))
UPDATE FATURA SET DOVIZKURU = 1 WHERE ISNULL(DOVIZKURU,0)=0 AND FATID>@FATID
UPDATE FATURA SET DOVIZ=ISNULL(DOVIZKODU,'TL') WHERE (DOVIZ IS NULL) OR (DOVIZ <> DOVIZKODU) AND FATID>@FATID
UPDATE FATURA SET KUR=ISNULL(DOVIZKURU,1) WHERE (KUR IS NULL) OR (KUR <> DOVIZKURU) AND FATID>@FATID
UPDATE FATURA SET FISHESAPID=CARIID WHERE (FISHESAPID IS NULL AND CARIID IS NOT NULL) OR (FISHESAPID <> CARIID) AND FATID>@FATID
UPDATE FATURA SET FISDURUMID = (CASE WHEN FIPTAL=1 THEN -2 ELSE ISNULL(DURUM,0) END) WHERE FATID>@FATID
UPDATE FATURA SET DTOPLAM = DBO.fn_RoundBanker(GTOPLAM/DOVIZKURU,2) WHERE FATID>@FATID
UPDATE FATURA SET DOVIZLI=0 WHERE FATID>@FATID

/*
UPDATE FATISL SET DOVIZ=ISNULL(DOVIZKODU,'TL') WHERE (DOVIZ IS NULL) OR (DOVIZ <> DOVIZKODU) AND FATID>@FATID
UPDATE FATISL SET KUR=ISNULL(DOVIZKURU,1) WHERE (KUR IS NULL) OR (KUR <> DOVIZKURU) AND FATID>@FATID
UPDATE FATISL SET NETTOPLAM = DBO.fn_RoundBanker(ADET*BFIYAT,2) - DBO.fn_IndirimTutar3lu(DBO.fn_RoundBanker(ADET*BFIYAT,2),SATIRIND,0,SATIRIND2,0,0,SATIRINDT) WHERE FATID>@FATID
*/

/*

UPDATE FATURA SET DOVIZKURU = 1 WHERE ISNULL(DOVIZKURU,0)=0
UPDATE FATURA SET DOVIZ=ISNULL(DOVIZKODU,'TL') WHERE (DOVIZ IS NULL) OR (DOVIZ <> DOVIZKODU)
UPDATE FATURA SET KUR=ISNULL(DOVIZKURU,1) WHERE (KUR IS NULL) OR (KUR <> DOVIZKURU)
UPDATE FATURA SET FISHESAPID=CARIID WHERE (FISHESAPID IS NULL AND CARIID IS NOT NULL) OR (FISHESAPID <> CARIID)
UPDATE FATURA SET FISDURUMID = (CASE WHEN FIPTAL=1 THEN -2 ELSE ISNULL(DURUM,0) END)
UPDATE FATURA SET DTOPLAM = DBO.fn_RoundBanker(GTOPLAM/DOVIZKURU,2)
UPDATE FATURA SET DOVIZLI=0

UPDATE FATISL SET DOVIZ=ISNULL(DOVIZKODU,'TL') WHERE (DOVIZ IS NULL) OR (DOVIZ <> DOVIZKODU)
UPDATE FATISL SET KUR=ISNULL(DOVIZKURU,1) WHERE (KUR IS NULL) OR (KUR <> DOVIZKURU)
UPDATE FATISL SET NETTOPLAM = DBO.fn_RoundBanker(ADET*BFIYAT,2) - DBO.fn_IndirimTutar3lu(DBO.fn_RoundBanker(ADET*BFIYAT,2),SATIRIND,0,SATIRIND2,0,0,SATIRINDT)


update FATURA
   set FISTURID = case 

                    when TURADI 
                      in ( 'ALĨ', 'ALIS' ) 
                    then  Cast( 51 as int ) 
                    
                    when TURADI 
                      in ( 'SATĨ ƯADE', 'SATIS IADE' ) 
                    then Cast( 54  as int )  
                           
                    when TURADI 
                      in ( 'ALĨ ƯADE', 'ALIS IADE' ) 
                    then Cast( 53 as int )
                    
                    when TURADI 
                      in ( 'PERAKENDE' ) 
                    then Cast( 69 as int ) 
                                  
                    else Cast( 52 as int )
                     
                  end

 where FISTURID is null
*/