All Forums Database
newbie_123 9 posts Joined 07/08
31 Jul 2008
Using INETERVAL With CASE Statement

Hello,The following statement works if it is just a selectselect case when grp_prpkg_exp_dt = '9999-12-31' then CAST('2007-12-31' AS DATE) - grp_prpkg_eff_dt else grp_prpkg_exp_dt - grp_prpkg_eff_dt end as num ,grp_prpkg_eff_dtfrom db_bidwd1v.dim_grp_prpkg_cvgsample 5but when I m trying to convert it to give me the number of months:select case when grp_prpkg_exp_dt = '9999-12-31' then CAST('2007-12-31' AS DATE) - grp_prpkg_eff_dt MONTH(4)else grp_prpkg_exp_dt - grp_prpkg_eff_dt MONTH(4) end as num ,grp_prpkg_eff_dt from db_bidwd1v.dim_grp_prpkg_cvgsample 5It gives me error.Can someone help me.Thanks in advance.

Adeel Chaudhry 773 posts Joined 04/08
31 Jul 2008

Hello,What error you are getting?Regards,Adeel

-- If you are stuck at something .... consider it an opportunity to think anew.

newbie_123 9 posts Joined 07/08
01 Aug 2008

It gives me syntax error saying that END should be there between grp_prpkg_eff_dt and MONTH

Fred 1096 posts Joined 08/04
01 Aug 2008

So add parentheses:CASE WHEN grp_prpkg_exp_dt = '9999-12-31' THEN (CAST('2007-12-31' AS DATE) - grp_prpkg_eff_dt MONTH(4)) ELSE (grp_prpkg_exp_dt - grp_prpkg_eff_dt MONTH(4)) END AS num

newbie_123 9 posts Joined 07/08
01 Aug 2008

COOL.. Thanks

You must sign in to leave a comment.