SQL Server Performance Forum – Threads Archive
Date question pleaseHey,
I am trying to create a stor proc for a 12 month billing report.
Lets say if i am running it in Mar ’07 i need it to show all the months from Mar 07 to Feb ’08
I am not sure how to do this.
If some one could help me it would be great.
Can you post sample report report what you want? MohammedU.
Please post your table DDL, sample data and the result that you want.
Something along these lines should get you going:
SELECT < list >
FROM < your billing_table >
WHERE your_datecolumn >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-12, 0)
GROUP BY DATEADD(MONTH, DATEDIFF(MONTH, 0, your_datecolumn), 0)
Microsoft SQL Server MVP