Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 assiff79 to get totals in 3rd columns

Author  Topic 

assiff79
Starting Member

7 Posts

Posted - 2014-07-19 : 05:11:15
i have a talble
debit credit totalcredit
25 10 10
20 35 45
30 40 85
look at 3rd colum 10=10
10+35 =45
40+45 =85

i want such results and also insertion statement

asif

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-07-19 : 05:21:42
[code]
; with cte as
(
select rn = row_number() over (order by <some column>), debit, credit
from talble
)
select debit, credit,
totalcredit = (select sum(credit) from cte x where x.rn <= c.rn)
from cte c
order by rn
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-07-19 : 06:31:52
just add the INSERT statement before the SELECT line to insert into your required table


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -