I'm trying to run a select statement in a reporting tool. And one of the select criteria is that it must return all data which was modified last month. So one of the coloumns has this date in the format YYYY/MM.
At the minute this has to be entered manually, as there is a user interface that can be used infront of the SQL.
I was wondering if there was a way to make this run automatically without user entry. i.e. replace:
WHERE date BETWEEN '2005/06' AND '2005/07'
to something more like
WHERE date >= ((sysdate, YYYY MM)MM, -1)
AND date < (sysdate, YYYY MM)
I know the above is a bad attempt but just trying to show the problem.
Thanks in advance.
- Moved by Lukasz Pawlowski -- MSMicrosoft employee Wednesday, August 19, 2009 5:14 PM (From:SQL Server Reporting Services)
Do you mean you want to show only the data corresponding to the current month?
If so, this might help:
WHERE MONTH(date) = MONTH(GETDATE()) AND YEAR(date) = YEAR(GETDATE())
Note that the date format doesn't matter if you use this code.
I hope this helps.
That sounds nearly about right but bascially im trying to compare it with a variable. and only want last months data.
WHERE TO_CHAR(var1, 'YYYY/MM') >= '2005/08'
AND TO_CHAR(var1, 'YYYY/MM') < '2005/09'
What i'm wanting to automate is the 2005/08 and the 2005/09, so i can compare value in that format.