All returned values from the CASE clauses should be strings (varchar
)
CASE b.religious_belief
WHEN 01 THEN 'none'
WHEN 05 THEN 'roman catholic'
ELSE 'Jedi'
END as MyColumnName
سؤال
I need to pass a varchar through a case statement in SQL. The Current data is an integer but I would like to display text.
CASE b.religious_belief
WHEN 01 THEN 'none'
WHEN 05 THEN 'roman catholic'
ELSE 0
END
I keep getting the error
Conversion failed when converting the varchar value 'none' to data type int.
المحلول
All returned values from the CASE clauses should be strings (varchar
)
CASE b.religious_belief
WHEN 01 THEN 'none'
WHEN 05 THEN 'roman catholic'
ELSE 'Jedi'
END as MyColumnName
نصائح أخرى
CASE b.religious_belief
WHEN 01 THEN 'none'
WHEN 05 THEN 'roman catholic'
ELSE ''
END
The return for the else
also needs to be a varchar, so if you're after a "zero" value, then either ''
or null
would be best.