Bu sql kodundan esinlenerek sorunu çözümleyebiliriz...
SELECT CLCARD.CODE AS KODU, CLCARD.DEFINITION_ AS ÜNVANI, SUM((1 - CLFLINE.SIGN) * CLFLINE.AMOUNT) - SUM(CLFLINE.SIGN * CLFLINE.AMOUNT)
AS BAKİYE, CASE WHEN SUM((1 - CLFLINE.SIGN) * CLFLINE.AMOUNT) - SUM(CLFLINE.SIGN * CLFLINE.AMOUNT) < 0 THEN SUM((1 - CLFLINE.SIGN)
* CLFLINE.AMOUNT) - SUM(CLFLINE.SIGN * CLFLINE.AMOUNT) * - 1 ELSE 0 END AS [Alacak Bakiye], CLCARD.ADDR1 AS Adres1,
CLCARD.ADDR2 AS Adres2, CLCARD.CITY AS Şehir, CLCARD.COUNTRY AS Ülke, CLCARD.POSTCODE AS PostaKodu, CLCARD.TELNRS1 AS TEL1,
CLCARD.TELNRS2 AS TEL2, CLCARD.FAXNR AS FAKS, CLCARD.TAXNR AS Vergi_No, CLCARD.TAXOFFICE AS Vergi_Dairesi,
CLCARD.DISCRATE AS iskonto, CLCARD.TOWN AS İLÇE, CLCARD.DISTRICT AS SEMT, CLCARD.STORECREDITCARDNO AS Plasiyer,
CLCARD.ACTIVE AS Statüsü
FROM LG_087_01_CLFLINE CLFLINE INNER JOIN
LG_087_CLCARD CLCARD ON CLFLINE.CLIENTREF = CLCARD.LOGICALREF AND CLFLINE.CANCELLED = 0
GROUP BY CLCARD.CODE, CLCARD.DEFINITION_, CLCARD.ADDR1, CLCARD.ADDR2, CLCARD.CITY, CLCARD.COUNTRY, CLCARD.POSTCODE,
CLCARD.TELNRS1, CLCARD.TELNRS2, CLCARD.FAXNR, CLCARD.TAXNR, CLCARD.TAXOFFICE, CLCARD.DISCRATE, CLCARD.TOWN,
CLCARD.DISTRICT, CLCARD.STORECREDITCARDNO, CLCARD.ACTIVE
HAVING (CLCARD.CODE LIKE 'T%') AND (CLCARD.ACTIVE = 0)
ORDER BY CLCARD.BAKİYE DESC