Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Nested case statement

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-05-10 : 10:55:52
I have the following statement in my script

CASE WHEN ERC2.TERMINATION_DATE IS NULL AND ERC.TAIL_PREM > 0 THEN 'I' ELSE ERC2.TERMINATION_DATE IS NOT NULL AND ERC.TAIL_PREM > 0 THEN 'C' ELSE ' 'END AS ERC_INSURED_STATUS_CODE


and I get the following error message
Server: Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'IS'.
Server: Msg 156, Level 15, State 1, Line 14
Incorrect syntax near the keyword 'WHERE'.

this tell me the nested case is wrong.. Any idea how to go about fixing this..

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-10 : 11:00:30
[code]CASE
WHEN ERC2.TERMINATION_DATE IS NULL AND ERC.TAIL_PREM > 0 THEN 'I'
WHEN ERC2.TERMINATION_DATE IS NOT NULL AND ERC.TAIL_PREM > 0 THEN 'C'
ELSE ' '
END AS ERC_INSURED_STATUS_CODE[/code]If you are used to C#/Java, it's like a switch (that does not fall through).
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 2013-05-10 : 11:04:41
Thanks James
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-10 : 13:18:12
You are very welcome - glad to help.
Go to Top of Page
   

- Advertisement -