I have a temp table with acct and balance; I would like to do a select statement that would add an additional column that has a cumulative
If the temp table is not too big, you can use this set based solution
SELECT acct, Balance, TB.cumBal
FROM #Temp1 T
(select sum(Balance) as cumBal from #Temp1 T2
and T1.Acct = T2.Acct) TB
ORDER BY Balance desc, Acct
select t1.acct, t1.Balance, (select sum(Balance) from tb t2 where
t2.acct <= t1.acct) as cumBal
from #Temp1 t1
order by t1.acct
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?