Date question please | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date question please

Hey,
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.
Thank you,
Mattie
Can you post sample report report what you want? MohammedU.
Moderator
SQL-Server-Performance.com
Please post your table DDL, sample data and the result that you want.
KH
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)

Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
]]>