SELECT CLCARD.CODE AS KODU, CLCARD.DEFINITION_ AS ÜNVANI,

(SUM((1 – CLFLINE.SIGN) * CLFLINE.AMOUNT) – SUM(CLFLINE.SIGN * CLFLINE.AMOUNT)) AS [BAKIYE] FROM

LG_001_01_CLFLINE CLFLINE INNER JOIN
LG_001_CLCARD CLCARD ON CLFLINE.CLIENTREF = CLCARD.LOGICALREF AND CLFLINE.CANCELLED = 0
GROUP BY CLCARD.CODE, CLCARD.DEFINITION_, CLCARD.ACTIVE
HAVING (CLCARD.CODE LIKE ‘%’) and (CLCARD.DEFINITION_ LIKE ‘%’)
AND (CLCARD.ACTIVE = 0) ORDER BY CLCARD.CODE DESC