SQL query for previous month - cannot use dateadd
Posted on 2008-10-16
We are running reports in an SAP add-on called XL Reporter. SAP is based on a SQL 2005 database.
We need to have a SQL query that will select data from a field based on the previous month. In the past we have accomplished this with the following query: WHERE [U_Date] >= '@Start_Date' AND [U_Date]<='@End_Date'. In order to schedule automated reporting, we need this query to be dynamic and based on the previous month from the date the report is run.
We have attempted to run using dateadd, but the XL Reporter software apparently does not recognize this command. We have been able to run a successful query using WHERE MONTH(U_Date) <= GETDATE(). Any ideas how to accomplish our objective using the GETDATE() function?