Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SELECT CASE NULL Comparison

Posted on 2008-10-08
4
Medium Priority
?
903 Views
Last Modified: 2012-06-27
Hi,

SELECT CASE field WHEN NULL THEN 'no' ELSE 'yes' FROM myTable

This sql statement gives me all 'yes' although there are many NULLS in the table.  Expect to see those 'no' values. Something very basic here!!

Please help.

0
Comment
Question by:sublimation
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
HuyBD earned 1000 total points
ID: 22667324
try this

SELECT CASE WHEN field is NULL THEN 'no' ELSE 'yes' FROM myTable

Open in new window

0
 
LVL 17

Expert Comment

by:HuyBD
ID: 22667333
CASE field WHEN...
just use for integer value
CASE field WHEN 1 then when 2.... end
0
 
LVL 4

Author Closing Comment

by:sublimation
ID: 31504158
Cheers!!!
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 22667347
--End should be added for the above query
SELECT CASE WHEN field is NULL THEN 'no' ELSE 'yes' END AS field FROM myTable
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

971 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