SELECT
[Cari Kodu]=CLCARD.CODE,
[Cari Adı]=CLCARD.DEFINITION_,
[Muhasebe Hesap Kodu]=ISNULL((SELECT CODE FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF)),0),
[Muhasebe Hesap Adı]=ISNULL((SELECT DEFINITION_ FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF)),0),
[Ocak Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_<=1 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Ocak Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_<=1 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Şubat Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=2 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Şubat Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=2 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Mart Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=3 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Mart Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=3 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Nisan Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=4 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Nisan Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=4 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Mayıs Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=5 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Mayıs Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=5 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Haziran Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=6 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Haziran Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=6 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Temmuz Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=7 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Temmuz Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=7 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Ağustos Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=8 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Ağustos Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=8 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Eylül Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=9 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Eylül Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=9 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Ekim Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=10 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Ekim Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=10 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Kasım Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=11 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Kasım Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=11 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Aralık Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_=12 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Aralık Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_=12 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0),
[Genel Muhasebe]=ISNULL((SELECT SUM(EMF.DEBIT-EMF.CREDIT) FROM LV_006_01_EMUHTOT EMF WHERE MONTH_<=12 AND TOTTYPE <=1 AND ACCOUNTREF IN(SELECT LOGICALREF FROM LG_006_EMUHACC WHERE LOGICALREF=(SELECT ACCOUNTREF FROM LG_006_CRDACREF WHERE TRCODE=5 AND CLCARD.LOGICALREF=CARDREF))),0),
[Genel Cari]=ISNULL((SELECT SUM(DEBIT-CREDIT) FROM LV_006_01_CLTOTFIL WHERE MONTH_<=12 AND TOTTYP=1 AND CLCARD.LOGICALREF=CARDREF),0)
FROM
LG_006_CLCARD AS CLCARD
WHERE CARDTYPE<>22