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!
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.
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)
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
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