Forum Discussion
SQL Statement Variable Date Range
- 6 years ago
The SQL will be little bit different with Oracle or SQL Server.
Here are the examples. Replace your WHERE clause/line.
ORACLE: WHERE M.Response_Date BETWEEN TRUNC(SYSDATE) AND TRUNC(ADD_MONTHS(SYSDATE,-24),'MONTH') SQL SERVER: WHERE M.Response_Date BETWEEN CAST(GETDATE() as DATE) AND DATEADD(MONTH,-24,CAST(GETDATE() as DATE))If this helps, mark it as a solution
Kudos are nice too
Hi VasTg,
I have very little experience with SQL, could you should me what that line of code would look like? I tried a variety of Date() and Sysdate() functions but always got an error message. I do not know what the database is, though I could ask someone to find out if its important (what types are there?).
Thanks for you help!
The SQL will be little bit different with Oracle or SQL Server.
Here are the examples. Replace your WHERE clause/line.
ORACLE:
WHERE M.Response_Date BETWEEN TRUNC(SYSDATE) AND TRUNC(ADD_MONTHS(SYSDATE,-24),'MONTH')
SQL SERVER:
WHERE M.Response_Date BETWEEN CAST(GETDATE() as DATE) AND DATEADD(MONTH,-24,CAST(GETDATE() as DATE))
If this helps, mark it as a solution
Kudos are nice too
- wasonj16 years agoFrequent Visitor
It was an SQL server, I had to swap the CAST and DATEADD calls but that worked perfectly. Thank you very much!