Aylık Bakiye Pİvot
CREATE VIEW VW_BAKİYEAY
AS
SELECT *
FROM ( SELECT CLNTC.CODE ,
CLNTC.DEFINITION_ ,
MONTH(CTRNS.DATE_) AS AY ,
ISNULL(SUM(CTRNS.SIGN * CTRNS.AMOUNT) - SUM(( 1
- CTRNS.SIGN )
* CTRNS.AMOUNT),
0) AS BAKIYE
FROM dbo.LG_016_CLCARD AS CLNTC
LEFT OUTER JOIN dbo.LG_016_01_CLFLINE AS CTRNS ON CLNTC.LOGICALREF = CTRNS.CLIENTREF
LEFT OUTER JOIN dbo.LG_016_01_CLFICHE AS CLFIC ON CTRNS.SOURCEFREF = CLFIC.LOGICALREF
AND CTRNS.TRANNO = CLFIC.FICHENO
WHERE ( CLNTC.CODE LIKE '120.%' )
GROUP BY CLNTC.CODE ,
CLNTC.DEFINITION_ ,
CTRNS.DATE_
) Tablo PIVOT
( SUM(BAKIYE) FOR AY IN ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12] ) ) PİVOTTABLOM;