YARDIMDA BULUNAN HERKESE TEŞEKKÜR EDERİM İHTİYACI OLAN İÇİN RAPORUN SON HALİ..;
/*Dövizli cari bakiye-satış-ödeme tarihleri*/
SELECT
LG_050_CLCARD.CODE AS [CARİ KODU],
LG_050_CLCARD.DEFINITION_ AS [CARİ ÜNVANI],
ROUND(SUM((CASE LG_050_02_CLFLINE.TRCURR WHEN 0 THEN (TRNET-(SIGN*TRNET))-(SIGN*TRNET) ELSE 0 END)),2) AS [BAKİYE (TL)],
ROUND(SUM((CASE LG_050_02_CLFLINE.TRCURR WHEN 1 THEN (TRNET-(SIGN*TRNET))-(SIGN*TRNET) ELSE 0 END)),2) AS [BAKİYE (USD)],
ROUND(SUM((CASE LG_050_02_CLFLINE.TRCURR WHEN 20 THEN (TRNET-(SIGN*TRNET))-(SIGN*TRNET) ELSE 0 END)),2) AS [BAKİYE (EUR)],
(SELECT TOP 1 DATE_ FROM LG_050_02_STLINE WHERE TRCODE IN (7,8) AND CLIENTREF=LG_050_CLCARD.LOGICALREF ORDER BY DATE_ DESC) AS [SON SATIS TARIHI],
(SELECT TOP 1 DATE_ FROM LG_050_02_CLFLINE WHERE TRCODE IN (1) AND CLIENTREF=LG_050_CLCARD.LOGICALREF ORDER BY DATE_ DESC) AS [SON ÖDEME TARIHI]
FROM LG_050_02_CLFLINE INNER JOIN LG_050_CLCARD ON LG_050_02_CLFLINE.CLIENTREF = LG_050_CLCARD.LOGICALREF
WHERE CODE LIKE 'MST%'
GROUP BY LG_050_CLCARD.CODE, LG_050_CLCARD.DEFINITION_,LG_050_CLCARD.LOGICALREF
ORDER BY LG_050_CLCARD.CODE