Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Null values when using case statement

Posted on 2005-05-12
2
Medium Priority
?
286 Views
Last Modified: 2010-05-18
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
Comment
Question by:rocketTendon
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 2000 total points
ID: 13989999
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
 
LVL 3

Author Comment

by:rocketTendon
ID: 13990038
Thanks... should have tried that... didn't even think about that.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question