Link to home
Start Free TrialLog in
Avatar of JosephEricDavis
JosephEricDavis

asked on

SQL Server - Case Statement resulting in NULL

I have a result set in my query that contains empty strings like ' '.  I would like to make those NULL in the select clause in my sql statement like this...

CASE WHEN Value = ' ' THEN NULL END AS Value

But when I do this I get this error...

None of the result expressions in a CASE specification can be NULL.

Is there a better way to accomplish what I'm after?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I suggest also trimming the value and testing for empty string instead:

select NULLIF( RTRIM(Value), '' ) as Value
from MyTable