Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Basic SQL editor question

Sunakshi
5 - Atom

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!

4 REPLIES 4
Felipe_Ribeir0
16 - Nebula

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.

Felipe_Ribeir0
16 - Nebula

Hi @Sunakshi 

 

Try this one for teradata DB


where EXTRACT(year FROM DateColumnBETWEEN EXTRACT(year FROM current_date - interval '3' year) AND EXTRACT(year FROM current_date)

simonaubert_bd
13 - Pulsar

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

Hi2023
8 - Asteroid

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

Labels