I really need to take what I have as a result of a CTE, and calculate the cummulative value of groups of data.
The dataset is:
PERIOD FT GROUP DEPT VALUE
1 Actual KINDER MATH 200
2 Actual KINDER MATH 363
3 Actual KINDER MATH 366
1 Budget KINDER MATH 457
2 Budget KINDER MATH 60
3 Budget KINDER MATH 158
1 Actual HIGHSCH ENGLISH 456
2 Actual HIGHSCH ENGLISH 745
3 Actual HIGHSCH ENGLISH 125
1 Budget HIGHSCH ENGLISH 364
2 Budget HIGHSCH ENGLISH 158
3 Budget HIGHSCH ENGLISH 200
6 Budget HIGHSCH ENGLISH 502
7 Budget HIGHSCH ENGLISH 650
1 Actual COLL ENGLISH 700
2 Actual COLL ENGLISH 540
3 Actual COLL ENGLISH 160
1 Budget COLL ENGLISH 820
2 Budget COLL ENGLISH 630
3 Budget COLL ENGLISH 800
What I want is an additional column that holds the cummulative amount for each FT, Group, Dept.
So basically, I would like it to look like this:
PERIOD FT GROUP DEPT VALUE ACC VALUE
1 Actual KINDER MATH 200 200
2 Actual KINDER MATH 363 563
3 Actual KINDER MATH 366 929
1 Budget KINDER MATH 457 457
2 Budget KINDER MATH 60 517
3 Budget KINDER MATH 158 675
1 Actual HIGHSCH ENGLISH 456 456
2 Actual HIGHSCH ENGLISH 745 1201
3 Actual HIGHSCH ENGLISH 125 1326
1 Budget HIGHSCH ENGLISH 364 364
2 Budget HIGHSCH ENGLISH 158 522
3 Budget HIGHSCH ENGLISH 200 722
1 Budget HIGHSCH ENGLISH 502 502
2 Budget HIGHSCH ENGLISH 650 1152
3 Budget HIGHSCH ENGLISH 336 1488
1 Actual COLL ENGLISH 700 700
2 Actual COLL ENGLISH 540 1240
3 Actual COLL ENGLISH 160 1400
1 Budget COLL ENGLISH 820 820
2 Budget COLL ENGLISH 630 1450
3 Budget COLL ENGLISH 800 2250
If I was in SQL 2012, I'd use something similar to this:
SELECT period
,ft
,group
,dept
,value
,CASE
WHEN FT = 'Actual' THEN SUM(value) OVER (PARTITION BY dept, group, ft ORDER BY period)
ELSE value
END AS AccValue
FROM myTable
However, I am on 2008 and can't use this method and am stumped on how to replicate this for my data.
Please can anyone help?