sandeep.mishra
sandeep.mishra

Reputation: 825

Case statement not working in mysql

I am writing a query to display an alias column with respect to a column value. below is my code

  CASE TRIM(channel_id)
  WHEN '' THEN 'General' 
  ELSE 'Specific'
END AS templateType

When the column channel id is empty/null the templateType column should show 'General' else should show 'Specific'

I am getting wrong output Can anyone help me please..?

Upvotes: 2

Views: 1705

Answers (2)

Rakesh Nayak
Rakesh Nayak

Reputation: 111

CASE TRIM(IFNULL(channel_id,''))
     WHEN '' THEN 'General' 
     ELSE 'Specific'
END AS templateType

Try this..

Upvotes: 3

gvee
gvee

Reputation: 17161

CASE WHEN channel_id > '' THEN
  'Specific' 
ELSE
  'General'
END As templateType

Aside:

SELECT CASE WHEN '' = '         ' THEN 'same' ELSE 'different' END

Results:

same

Upvotes: 0

Related Questions