I need to create a report that checks through the previous 12 months only. I have this code which is working:
DECLARE @date DATETIME = DATEADD(year,-1,GETDATE()) WHILE @date < GETDATE() BEGIN --do marvelous things SET @date = DATEADD(MONTH,1,@date) END
...however it brings the results back starting from June 2014 (as it is June 2015 today, obviously).
I would like the code to bring back results starting from June 2015 and then work backwards to June 2014, but am not sure how to do this...
Am using SQL Server 2012.