2

I am running a simple query having SELECT CASE

SELECT DEPT_ID, DEPT_NAME = 
    CASE DEPT_NAME
        WHEN 'PBG' THEN 'Best Dept'
        ELSE 'Usual Dept'
    END
FROM DEPARTMENTS;

However, the output is not satisfactory. All 0 is coming in output

enter image description here

What is wrong in query ?

Otherwise the table has below data

SELECT * FROM DEPARTMENTS;

enter image description here

1 Answer 1

5

Move the column alias DEPT_NAME. It should be placed after the case expression, not before:

SELECT DEPT_ID, 
    CASE DEPT_NAME
        WHEN 'PBG' THEN 'Best Dept'
        ELSE 'Usual Dept'
    END as DEPT_NAME 
FROM DEPARTMENTS;
Sign up to request clarification or add additional context in comments.

1 Comment

Great. (Did you perhaps use SQL Server specific syntax?)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.