I'm trying to calc a running total by each person in my table. I would like to do this for the Paid column.
Here are the field I have in my table Date, ID, Billed, Paid.
This is the code I'm using. Right now it's calculating a total for each ID and putting that number in each line. (e.g. If ID=1 had 20 in Jan and 20 in Feb, it would put 40 for the running total in Jan and Feb. I would like it to be 20 in Jan and 40 in Feb.)
What am I doing wrong here?
Btw, I'm using 2008. I've read there's some nice handling for this in 2012 but I don't have that. Thanks.
Here are the field I have in my table Date, ID, Billed, Paid.
This is the code I'm using. Right now it's calculating a total for each ID and putting that number in each line. (e.g. If ID=1 had 20 in Jan and 20 in Feb, it would put 40 for the running total in Jan and Feb. I would like it to be 20 in Jan and 40 in Feb.)
What am I doing wrong here?
Btw, I'm using 2008. I've read there's some nice handling for this in 2012 but I don't have that. Thanks.
Code:
SELECT
t1.[Date]
,t1.[ID]
,t1.[Billed]
,t1.[Paid]
,SUM(t2.[New_Mbr_Med_CS]) as 'Ttl_Med_CS'
FROM #localtemp As t1
INNER JOIN #localtemp as t2
ON t1.[ID] = t2.[ID]
GROUP BY
t1.[Date]
,t1.[ID]
,t1.[Billed]
,t1.[Paid]
ORDER BY
t1.[ID]
,t1.[Date]