SELECT CONVERT(VARCHAR,PT.DATE_,104)'Vade Tarihi', CC.CODE CARİ_KOD, CC.DEFINITION_ ÜNVAN, CASE(PT.MODULENR) WHEN 3 THEN 'SİPARİŞ' WHEN 4 THEN 'FATURA' WHEN 5 THEN 'CARİ FİŞ' WHEN 6 THEN 'Çek - Senet' WHEN 7 THEN 'BANKA' WHEN 10 THEN 'KASA' ELSE 'DİĞER' END 'TÜR', --C.MODULENR, --Bu satır Pasif Yapılabilir.CASE WHEN (PT.MODULENR=4) AND (PT.TRCODE=2) THEN 'PER.SATIŞ.İADE.FTR' WHEN (PT.MODULENR=5) AND (PT.TRCODE=3) THEN 'BORÇ DEKONTU' WHEN (PT.MODULENR=7) AND (PT.TRCODE=3) THEN 'Gelen Havale' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) THEN 'SATIŞ SİPARİŞİ'END 'Fiş Türü', PT.DOCODE [Belge No], PT.MODULENR MODÜL, PT.TRCODE 'TRCODE',CASE WHEN PT.SIGN ='1' THEN 'ALACAK' WHEN PT.SIGN ='0' THEN 'BORÇ' END DURUM, CASE WHEN MONTH(PT.DISCDUEDATE)= '1' THEN 'Ocak' WHEN MONTH(PT.DISCDUEDATE)= '2' THEN 'Şubat' WHEN MONTH(PT.DISCDUEDATE)= '3' THEN 'Mart' WHEN MONTH(PT.DISCDUEDATE)= '4' THEN 'Nisan' WHEN MONTH(PT.DISCDUEDATE)= '5' THEN 'Mayıs' WHEN MONTH(PT.DISCDUEDATE)= '6' THEN 'Haziran' WHEN MONTH(PT.DISCDUEDATE)= '7' THEN 'Temmuz' WHEN MONTH(PT.DISCDUEDATE)= '8' THEN 'Ağustos' WHEN MONTH(PT.DISCDUEDATE)= '9' THEN 'Eylül' WHEN MONTH(PT.DISCDUEDATE)= '10' THEN 'Ekim' WHEN MONTH(PT.DISCDUEDATE)= '11' THEN 'Kasım' WHEN MONTH(PT.DISCDUEDATE)= '12' THEN 'Aralık'END AY,PT.TRCODE FİŞ_TÜRÜ, SUM(PT.TOTAL) TUTAR,PT.PAID AS KAPANAN,SUM(PT.TOTAL)-PT.PAID AS FARK,CASE WHEN (PT.MODULENR<>3) AND (PT.TRCODE<>1) AND (SUM(PT.TOTAL)-PT.PAID<>0) THEN 'AÇIK İŞLEM KONTROL ET' WHEN (PT.MODULENR<>3) AND (PT.TRCODE<>1) AND (SUM(PT.TOTAL)-PT.PAID=0) THEN 'MANUEL KAPATILMIŞ' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) AND (SUM(PT.TOTAL)-PT.PAID=0) THEN 'FATURA KESİLMİŞ' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) AND (SUM(PT.TOTAL)-PT.PAID>0) THEN 'FATURA KES'END FATURA_DURUMU,PT.FICHEREF AS [Fiş Referansı]FROM LG_011_01_PAYTRANS AS PT INNER JOIN LG_011_CLCARD AS CC ON PT.CARDREF = CC.LOGICALREFWHERE CC.DEFINITION_ LIKE 'XXXXXXX' AND [FATURA_DURUMU] ='FATURA KES' -- I think this line second and got to do a modification and syntax.GROUP BY CC.CODE, PT.TRCODE, PT.DISCDUEDATE, PT.TOTAL, CC.DEFINITION_, PT.MODULENR, PT.SIGN, PT.DATE_, PT.DOCODE, PT.PAID, PT.FICHEREFORDER BY PT.DATE_

USE test1DECLARE @FATURA_SAY INTSELECT CONVERT(VARCHAR,PT.DATE_,104)'Vade Tarihi', CC.CODE CARİ_KOD, CC.DEFINITION_ ÜNVAN, CASE(PT.MODULENR) WHEN 3 THEN 'SİPARİŞ' WHEN 4 THEN 'FATURA' WHEN 5 THEN 'CARİ FİŞ' WHEN 6 THEN 'Çek - Senet' WHEN 7 THEN 'BANKA' WHEN 10 THEN 'KASA' ELSE 'DİĞER' END 'TÜR', --C.MODULENR, --Bu satır Pasif Yapılabilir.CASE WHEN (PT.MODULENR=4) AND (PT.TRCODE=2) THEN 'PER.SATIŞ.İADE.FTR' WHEN (PT.MODULENR=5) AND (PT.TRCODE=3) THEN 'BORÇ DEKONTU' WHEN (PT.MODULENR=7) AND (PT.TRCODE=3) THEN 'Gelen Havale' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) THEN 'SATIŞ SİPARİŞİ'END 'Fiş Türü', PT.DOCODE [Belge No], PT.MODULENR MODÜL, PT.TRCODE 'TRCODE',CASE WHEN PT.SIGN ='1' THEN 'ALACAK' WHEN PT.SIGN ='0' THEN 'BORÇ' END DURUM, CASE WHEN MONTH(PT.DISCDUEDATE)= '1' THEN 'Ocak' WHEN MONTH(PT.DISCDUEDATE)= '2' THEN 'Şubat' WHEN MONTH(PT.DISCDUEDATE)= '3' THEN 'Mart' WHEN MONTH(PT.DISCDUEDATE)= '4' THEN 'Nisan' WHEN MONTH(PT.DISCDUEDATE)= '5' THEN 'Mayıs' WHEN MONTH(PT.DISCDUEDATE)= '6' THEN 'Haziran' WHEN MONTH(PT.DISCDUEDATE)= '7' THEN 'Temmuz' WHEN MONTH(PT.DISCDUEDATE)= '8' THEN 'Ağustos' WHEN MONTH(PT.DISCDUEDATE)= '9' THEN 'Eylül' WHEN MONTH(PT.DISCDUEDATE)= '10' THEN 'Ekim' WHEN MONTH(PT.DISCDUEDATE)= '11' THEN 'Kasım' WHEN MONTH(PT.DISCDUEDATE)= '12' THEN 'Aralık'END AY,PT.TRCODE FİŞ_TÜRÜ, SUM(PT.TOTAL) TUTAR,PT.PAID AS KAPANAN,SUM(PT.TOTAL)-PT.PAID AS FARK,CASE WHEN (PT.MODULENR<>3) AND (PT.TRCODE<>1) AND (SUM(PT.TOTAL)-PT.PAID<>0) THEN 'AÇIK İŞLEM KONTROL ET' WHEN (PT.MODULENR<>3) AND (PT.TRCODE<>1) AND (SUM(PT.TOTAL)-PT.PAID=0) THEN 'MANUEL KAPATILMIŞ' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) AND (SUM(PT.TOTAL)-PT.PAID=0) THEN 'FATURA KESİLMİŞ' WHEN (PT.MODULENR=3) AND (PT.TRCODE=1) AND (SUM(PT.TOTAL)-PT.PAID>0) THEN 'FATURAYI KES'END FATURA_DURUMU,PT.FICHEREF AS [Fiş Referansı]FROM LG_011_01_PAYTRANS AS PT INNER JOIN LG_011_CLCARD AS CC ON PT.CARDREF = CC.LOGICALREFWHERE CC.DEFINITION_ LIKE 'Ersoy AYDIN'GROUP BY CC.CODE, PT.TRCODE, PT.DISCDUEDATE, PT.TOTAL, CC.DEFINITION_, PT.MODULENR, PT.SIGN, PT.DATE_, PT.DOCODE, PT.PAID, PT.FICHEREFORDER BY PT.DATE_