• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

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
0
JosephEricDavis
Asked:
JosephEricDavis
  • 2
1 Solution
 
knightEknightCommented:
try the NULLIF function

select NULLIF(Value,' ') as Value
from MyTable
0
 
knightEknightCommented:
I suggest also trimming the value and testing for empty string instead:

select NULLIF( RTRIM(Value), '' ) as Value
from MyTable
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now