2

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

1
  • can you give sample data? Commented Sep 17, 2013 at 13:07

2 Answers 2

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

Try this..

Sign up to request clarification or add additional context in comments.

Comments

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

Aside:

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

Results:

same

1 Comment

@sandeep.mishra Just note that this method requires no extra functions i.e. TRIM() and IFNULL()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.