Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server
hello friends,
 

i have one table and there is record like that
 

ID Amount
1 100
2 500
3 1500
4 5800
 
now i want to get record like
1 100 100
2 500 600
3 1500 2100
4 5800 7900
 

can any one help me for this query to get record like this...!!
 
Thank You all...!!
Posted 3-Oct-12 0:28am
Comments
Zoltán Zörgő at 3-Oct-12 5:30am
   
You want a running summary?
Yatin chauhan at 3-Oct-12 6:21am
   
Yes Zoltan....!!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have a look here for a running total example
 
http://www.techrepublic.com/article/running-totals-in-sql-server-queries/6158593[^]
 
Or a code project article here
 
Calculating simple running totals in SQL Server[^]
  Permalink  
Comments
Yatin chauhan at 3-Oct-12 6:04am
   
Thank a Lot Dylan Morley....!!!!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

insert into @t
select 1,10
union
select 2,12
union
select 3,3
union
select 4,15
union
select 5,23
 

select * from @t
 
select t1.id, t1.SomeNumt, SUM(t2.SomeNumt) as sum
from @t t1
inner join @t t2 on t1.id >= t2.id
group by t1.id, t1.SomeNumt
order by t1.id
 

Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you need running totals in just T-SQL, start from here: http://www.sqlhacks.com/Summary/Running_Total[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100