I’m trying to basically dynamically set two variables (@month and @year) to be whatever the previous month and year were.
So in today’s case @month = 7 and @year = 2012
But I want something safe for the year roll around, so if it’s 1/1/2013 I would get @month = 12 and @year = 2012.
Thanks!
This is what I have.
declare @month int
declare @year int
set @month = month (getDate ())-1
set @year = 2012
You can use DATEADD to subtract a month from the current date, then grab the
MONTHandYEARportions: