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

Null values when using case statement

I have the following sql:

Select sale_price,
'SaleEndDate' = CASE CONVERT(VARCHAR(12),sale_price)
         WHEN null THEN null
         WHEN '' then ''
         ELSE CONVERT(VARCHAR(10), [Sale End], 120)
      END
from mytable

However... the sql is still returning a value for the else statement even if the sale_price IS indeed null (the sale_price shows as null in the result set).

What am I missing?
0
rocketTendon
Asked:
rocketTendon
1 Solution
 
rafranciscoCommented:
Try this:

Select sale_price,
'SaleEndDate' = CASE WHEN CONVERT(VARCHAR(12),sale_price) IS NULL THEN NULL
                                WHEN CONVERT(VARCHAR(12),sale_price) = '' THEN ''
                                ELSE CONVERT(VARCHAR(10), [Sale End], 120)
                        END
from mytable
0
 
rocketTendonAuthor Commented:
Thanks... should have tried that... didn't even think about that.
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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