I've got a SQL statement (SQL Server Management Studio) that I'm passing data into a where-statement into via a dashboard software. The users can select the year (2013 or now 2014) and also the month (which gets passes as a numeric value - so December = 12). I need to adjust the statement to where I get the last 3 months from the year/month they select. Before, b/c the SQL statement was only dealing with 2013 data, it was just the following:
YEAR(Main.ActivityDate) = '@Request.parmYear~'
AND (Month(Main.ActivityDate) Between ('@Request.parmMonth~'-2) and '@Request.parmMonth~')
Normally, parmYear = 2013 and then whatever month they select, it will grab 2 months prior through the current month.
Now, b/c it's January 2014, I need to to grab January 2014 + December 2013 + November 2013. I'm wondering how to adjust the statement to make this happen dynamically.
Thoughts?