Question : How do I add a Running Total and Historical Dates from a transaction table using SQL?

Hi,

I've run into an issue that I can't figure out a solution for. I have a table called 'Transactions' that has account number, transaction date and amount. The account number is not unique - it can be entered multiple times with various dates and/or amounts. What I need is to take this 'Transactions' table and create a new table that will have the account number, a running total of the amount and the month the transaction occurred. Then I need that record repeated for each month after that until the next transaction for that account number occurs. I would then need this transaction's amount added to the running total and the month it occurs and then repeated until the next transaction and so forth continuing through the current month. The table has too many records to try to do this manually. I am attaching a spreadsheet that shows an example of what I have and then what I need it to do. Any help would be greatly appreciated as I am completely stuck!
 
What I have vs. What I need
 

Answer : How do I add a Running Total and Historical Dates from a transaction table using SQL?

wrong alias there
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
select t1.[Account Number],
	dateadd(m, t2.number, 0) as tdate
into #tem
from (
	select 	[Account Number], 
		datediff(m, 0, [Transaction Date]) as tdate, 
		datediff(m, 0, getdate()) as mdate
	from yourtable a
	where [Transaction Date] = (select min([Transaction Date]) from yourtable where [Account Number] = a.[Account Number])
) t1
cross join (select number from enum_table) t2
where t2.number between t1.tdate and t1.mdate
Random Solutions  
 
programming4us programming4us