views:

21

answers:

2

Is there any nice way to get subsums in one query for data like this in sql server 2000?

Input:
Date       Value
2008-06-20 10
2008-08-20 20
2008-10-05 5
2008-10-09 30

Desired output:
10    --sum of 1st value
30    --sum of 1st and 2nd values..
35
65
A: 

This article covers your question (three times actually!). Interesting that the elegant approach is the slowest.

Steve Homer
Thanks. I thought that cursors are evil and one query would be better..
Dooh
A: 

You'll also find this link useful as it describes how to calculate a running total without using a cursor.

Kane