Basic SQL editor question
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello,
I am trying to get previous 3 year data from current date. I need to worfklow to alFor example - from today the data needed will be 01/01/2019 - 10/21/22. I am trying to write this query in SQL editor. What is the best way to query this?
Thanks in advance!
- Labels:
- Date Time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Sunakshi
If you are using SQL Server, try this on your WHERE Clause
WHERE DateColumn >= DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE())-3, 0)
For other DB`s, you must see how is the syntax to do the same thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @Sunakshi
Try this one for teradata DB
where EXTRACT(year FROM DateColumn) BETWEEN EXTRACT(year FROM current_date - interval '3' year) AND EXTRACT(year FROM current_date)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
As mentioned previously, sql editor, in-db syntax for formula, filter or even connect in-db must be writtent in the database language. These databases uses mainly flavor of SQL language.... but the point is every database makes its own interpretation of the norm and they may differ somehow.
For sql norm, you can try https://www.w3schools.com/sql/sql_where.asp
And for filters on date, I suggest you find the documentation of your database. It can vary a lot, and more frustrating, it can even depends on the database configuration (ex : NLS for Oracle)
Best regards,
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
for TERADATA DB, in the SQL Editor,
I am trying to get 1 month of previous data every time the report is ran-- how would I write this out?
thanks
