I have a table with the following columns: reportDate DATETIME and losses CURRENCY and of course the ID column.
How do I write a query that will return a table with a running total of the losses column? Each date will have multiple entries so i think they will need use Sum() for each date. I know this has to do with the DSum function but im still lost on this one. It should look something like
Month Losses Cum
----- ------ -----
Jan $3,000 $3,000
Feb $2,000 $5,000
Mar $1,500 $6,500
Having a sql statement that's not Access specific would be the most help to me, I think. But all solutions are appreciated. Thanks for the help.
I found table and field names in the edit history of your question, so used those names in this answer. You didn't provide record_matYields sample data, so I created my own and hope it is suitable:
First I created qryMonthlyLosses. Here is the SQL and the output:
I used that first query to create another, qryCumulativeLossesByMonth:
Finally I used qryCumulativeLossesByMonth as the data source in a query which transforms the output to match your requested format.
You could probably revise this into a single query using subqueries instead of the separate named queries. I used this step-wise approach because I hoped it would be easier to understand.
Edit: I returned the full name with the MonthName() function. If you want the abbreviated month name, pass True as a second parameter to that function. Either of these should work:
This will do it for you in one SQL without using temporary tables
This page looks good for you:
http://support.microsoft.com/kb/290136
FYI, I wrote the following T-SQL against SQL Server before:
The result: