Case Statement - multiple parameters for same field

General
Enthusiast

Case Statement - multiple parameters for same field

Hi,

I've tried to get the below to work but keep getting erros about '('s in the wrong place etc, I have tried as many variation as I can think of but I think the answer is right in front of me but I can't see it!! - hope someone can help. 

Can anyone advise where this code is wrong & how to get it to work?

Thanks

SELECT 

CASE

 WHEN A.START_DT < '2012-07-31 23:59:59'

AND (A.END_DT >  '2012-07-31 23:59:59'

OR A.END_DT IS NULL) THEN '201207',

WHEN A.START_DT < '2012-08-31 23:59:59'

AND (A.END_DT >  '2012-08-31 23:59:59'

OR A.END_DT IS NULL) THEN '201208'

END AS Month_Id,

From Table_A

1 REPLY
Enthusiast

Re: Case Statement - multiple parameters for same field

Got it !!

No comma between the clauses ...

CASE 

WHEN A.START_DT < '2012-07-31 23:59:59'
AND (A.END_DT >  '2012-07-31 23:59:59'
OR A.END_DT IS NULL) THEN '201207'
    
 WHEN A.START_DT < '2012-08-31 23:59:59'
AND (A.END_DT >  '2012-08-31 23:59:59'
OR A.END_DT IS NULL) THEN '201208'
    
END AS Month_Id

From Table_A