Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

WHERE LAST_UPDATE IS THE PREVIOUS QUARTER

LisaLeach
7 - Meteor

I am currently using this in my WHERE Clause to pull records for the previous month.

 

where extract(year from GFTBPM_70872_APP.CRV_INV_HEADER.CREATED_ON) = extract(year from sysdate) And extract(month from GFTBPM_70872_APP.CRV_INV_HEADER.CREATED_ON) = extract(month from sysdate) - 1

 

It was successfully changed to previous week.

 

where extract(year from GFTBPM_70872_APP.CRV_INV_HEADER.LAST_UPDATED_ON) = extract(year from sysdate) And extract(day from GFTBPM_70872_APP.CRV_INV_HEADER.LAST_UPDATED_ON) = extract(day from sysdate) – 7

 

How would this be updated to look for the previous quarter?  I keep getting errors.

4 REPLIES 4
OllieClarke
16 - Nebula
16 - Nebula

Hi @LisaLeach 

I think we need more information to help out here. Which database are you connecting to (e.g. Snowflake/MySQL/Microsoft SQL Server)?
Also, as this is an Alteryx forum, are you using this SQL in a workflow/tool? If so which tool/where in your workflow?

You say you're getting errors. What do the errors say?

 

Ollie

LisaLeach
7 - Meteor

Hi.  It is an Oracle database. I was able to solve it this way.

 

where (Extract(Year from h.CREATED_ON) = Extract(Year from SysDate ) and Extract(Month from h.CREATED_ON) = Extract(Month from SysDate) - 3)
or (Extract(Year from h.CREATED_ON) = Extract(Year from SysDate) and Extract(Month from h.CREATED_ON) = Extract(Month from SysDate) - 2)
or (Extract(Year from h.CREATED_ON) = Extract(Year from SysDate ) and Extract(Month from h.CREATED_ON) = Extract(Month from SysDate) - 1)

 

This gave me all the records that were created 3, 2 and 1 month ago.  The report is run the first of each quarter so this will work fine enough.  I wont work if I have to run it off cycle.

 

There must be another way.

dreldrel
8 - Asteroid

Hi, could you please share more details about your error message or a sample?

OllieClarke
16 - Nebula
16 - Nebula

@LisaLeach 
There is indeed another way. (from here: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/ROUND-and-TRUNC-Date-Functions.h...)


where trunc(CREATED_ON,'Q') = trunc(dateadd(sysdate,,-3),'Q'))


This checks whether the quarter of Created_on is the same as the quarter of 3 months ago

 

Hope that helps,

 

Ollie

Labels
Top Solution Authors