Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add column

Status
Not open for further replies.

jmk418

MIS
May 24, 2004
99
US
Hi all
In my data set I am returning the hour and the number of times something happens in an hour so it looks like this

Col 1 Col 2
0 2
1 4
2 2

and so on up till 23

what I want is a running total in another column so that the data will look something like

Col 1 Col 2 Col 3
0 2 2
1 4 6
2 2 8

I was looking at the rank and dense_rank functions without any luck. Is there a way to do this in a simple function?

Thanks in advance
Jeremy

 
Code:
SELECT YourTable.Col1,
       YourTable.Col2,
       SUM(Tbl1.Col2) AS Col3
FROM YourTable
LEFT JOIN YourTable Tbl1 ON YourTable.Col1 <= Tbl1.Col1

NOT TESTED!!!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
I was not able to get this to work but I think it was because I was using nested queries and not just pulling all the data from a table. I ended up getting the results I wanted in Reporting Services using the RunningValue function.
Thanks for the suggestion though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top