0
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.

1
  • For one thing, you are using double quotes for a string, when the accepted delimiter is single quotes. Commented Oct 6, 2020 at 0:32

1 Answer 1

1

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 have CASE <value>, but not both.
  • Strings are delimited by single quotes.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks everybody for all the feedback and pointers. I was able to edit @Gordon Linoff answer to do what i wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.