Annie Jeba Annie Jeba - 1 month ago 6
SQL Question

Case Statement on Multiple conditions in Oracle

CASE test
WHEN NULL and SUBSTR(('99999999' - Tst_Date),1,4) > 2009 THEN 'Medi'
WHEN NULL and SUBSTR(('99999999' - Tst_Date),1,4) < 2009 THEN 'hills'
ELSE test
END AS "Phy"


Am i missing something in the above case statement?
I keep on getting 00905. 00000 - "missing keyword" error?

Answer

Your syntax is a little bit off. Use this:

CASE WHEN test IS NULL AND SUBSTR(('99999999' - Tst_Date),1,4) > 2009 THEN 'Medi'
     WHEN test IS NULL AND SUBSTR(('99999999' - Tst_Date),1,4) < 2009 THEN 'hills'
     ELSE test
END AS "Phy"
Comments