All Forums Database
Ghalia 11 posts Joined 12/15
10 Feb 2016
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,

dins2k2 51 posts Joined 05/13
10 Feb 2016

Ghalia,
 
Please check the below link.
https://forums.teradata.com/forum/database/add-months-vs-interval
HTH.
 
Thanks,
Dinesh

dnoeth 4628 posts Joined 11/04
10 Feb 2016

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)

 

Dieter

Ghalia 11 posts Joined 12/15
11 Feb 2016

Hello everyone,
 
Thank you :-)
 
Ghalia

You must sign in to leave a comment.