user3749447
user3749447

Reputation: 299

combining these 2 case when statements

The below case statement works, returning Yes where value = 1 for col1. How can I include the 2nd when for col2?

SELECT CASE 
WHEN col1= '1' THEN 'Yes' ELSE 'No' END 
FROM PROVIDERS
WHERE NAME = 'Hospital1'

The below gives erros

 SELECT CASE 
(WHEN col1= '1' THEN 'Yes' ELSE 'No' END) as 1st,
(WHEN col2= '1' THEN 'Yes' ELSE 'No' END) as 2nd
    FROM PROVIDERS
WHERE NAME = 'Hospital1'

Upvotes: 0

Views: 31

Answers (2)

Kris Gruttemeyer
Kris Gruttemeyer

Reputation: 872

Formatted correctly:

SELECT CASE 
        WHEN col1 = '1'
            THEN 'Yes'
        ELSE 'No'
        END AS 1st
    ,CASE 
        WHEN col2 = '1'
            THEN 'Yes'
        ELSE 'No'
        END AS 2nd
FROM PROVIDERS
WHERE NAME = 'Hospital1'

Upvotes: 2

Jesuraja
Jesuraja

Reputation: 3844

CASE is missed in Second column

SELECT 
       CASE WHEN col1 = '1' THEN 'Yes' ELSE 'No' END AS 1st,
       CASE WHEN col2 = '1' THEN 'Yes' ELSE 'No' END AS 2nd
FROM   PROVIDERS
WHERE  NAME = 'Hospital1'

Upvotes: 2

Related Questions