Extract VS INTERVAL

Database
Enthusiast

Extract VS INTERVAL

Hello,

I want to rewrite this condition :

where  ((extract(month from ID_JOUR) between extract(month from (add_months(date,- 2))) AND extract(month from (add_months(date,- 1)))) OR extract(month from (add_months(date,- 2))) > extract(month from (add_months(date,- 1))) )

Any idea please ?

Regards,

3 REPLIES
Enthusiast

Re: Extract VS INTERVAL

Ghalia,

Please check the below link.

https://forums.teradata.com/forum/database/add-months-vs-interval

HTH.

Thanks,

Dinesh

Senior Apprentice

Re: Extract VS INTERVAL

A WHERE-condition should be sargable (https://en.wikipedia.org/wiki/Sargable), there should be no function/calculation applied to a column.

Better move the calculation to the BETWEEN:

where
ID_JOUR between oadd_months(last_day(current_date),-3)+1
and oadd_months(last_day(current_date),-1)
Enthusiast

Re: Extract VS INTERVAL

Hello everyone,

Thank you :-)

Ghalia