Código SQL:
Ver originalCREATE TABLE #temp
(
accdate datetime,
DebitCredit VARCHAR(20),
Account INT,
Amount INT
)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110101','D',11200,1500)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110101','C',11200,60)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110102','D',11200,400)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110102','C',11200,100)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110102','C',11200,300)
INSERT INTO #temp (AccDate,DebitCredit,Account,Amount) VALUES ('20110102','C',11200,250)
SELECT t1.accdate,t1.account,t1.DebitCredit,t1.amount,SUM(t2.amount) suma
FROM(
SELECT ROW_NUMBER() OVER(partition BY account ORDER BY account) AS rn, * FROM #temp
) AS t1 INNER JOIN
(
SELECT ROW_NUMBER() OVER(partition BY account ORDER BY account) AS rn, * FROM #temp
) AS t2 ON (t1.rn>=t2.rn)
GROUP BY t1.accdate,t1.Account,t1.rn,t1.Amount,t1.DebitCredit
Prueba con esto, encontre la idea en este foro:
http://stackoverflow.com/questions/2...cumulative-sum
saludos!