BU tabloya cari hesap hareketlerindeki son işlem tarihini de ekleyebilirmiyiz?
DECLARE @FRMNO NVARCHAR(20)
DECLARE @DNM NVARCHAR(20)
SET @FRMNO = '022' /* 022*/
SET @DNM = '04' /* 04*/
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = N'
SELECT DISTINCT CLNTC.CODE, CLNTC.DEFINITION_, ISNULL( SUM((1-CTRNS.SIGN)*CTRNS.AMOUNT),0) AS BORC,ISNULL(SUM(CTRNS.SIGN*CTRNS.AMOUNT),0) AS ALACAK,
SUM(CTRNS.SIGN*CTRNS.AMOUNT)-(SUM((1-CTRNS.SIGN)*CTRNS.AMOUNT)) AS BAKIYE
FROM LG_'+@FRMNO+'_CLCARD CLNTC
LEFT OUTER JOIN LG_'+@FRMNO+'_'+@DNM+'_CLFLINE CTRNS ON (CLNTC.LOGICALREF = CTRNS.CLIENTREF)
LEFT OUTER JOIN LG_'+@FRMNO+'_'+@DNM+'_CLFICHE CLFIC ON ((CTRNS.SOURCEFREF = CLFIC.LOGICALREF) AND (CTRNS.TRANNO = CLFIC.FICHENO))
GROUP BY CLNTC.CODE, CLNTC.DEFINITION_
ORDER BY CLNTC.CODE, CLNTC.DEFINITION_ '
EXECUTE( @SQL)