SELECT first_name, last_name, manager_id CASE manager_id WHEN manager_id IS null THEN "pip" End manager_id FROM assgnssql.employees;
I am trying to select list of employees, but i know some employees do not have manager_id, for these employees without manager_id (null) i want the result to display “pip” while for the rest it displays original info.
Advertisement
Answer
The code you want is probably:
SELECT first_name, last_name, manager_id (CASE WHEN manager_id IS null THEN 'pip' ELSE manager_id END) as manager_id FROM assgnssql.employees;
Or more simply:
SELECT first_name, last_name, manager_id COALESCE(manager_id, 'pip') as manager_id FROM assgnssql.employees;
The two significant issues are:
- Your
CASE
syntax is messed up. Either you use comparisons or you haveCASE <value>
, but not both. - Strings are delimited by single quotes.