I want to return multiple value in the THEN clause of CASE statement

5 pts.
Tags:
CASE statement
SQL
I want to return multiple value in the THEN clause of CASE statement. SELECT c.company_code, c.com_inactive_flag, e.emp_no FROM company c, employees e WHERE c.com_code = e.com_code AND e.emp_status in ( (CASE c.com_inactive_flag WHEN 'N' THEN 'A' WHEN 'Y' THEN 'B,C' END) If the flag is N all those employees will be retrieved whoe has status A otherwise all those who have B and C flag should be retrieved. But because I have 'B,C' so it will not return anything. Is there anyway I can put 'B,C' etc. instead of just one value like 'B'.

Answer Wiki

Thanks. We'll let you know when a new response is added.

That isn’t going to work as written. The output of a CASE statement has to be a single value, but for it to work for the IN, each letter has to be a seperate value.

I’d recommend setting up a joining table between the e.emp_status and c.com_inactive_flag columns so that you can find the matches via an inner join instead of the CASE statement.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: