Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
CASE and IS NULL
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
gracie  
View profile  
 More options Dec 12 2007, 6:33 pm
Newsgroups: microsoft.public.sqlserver.programming
From: gracie <gra...@discussions.microsoft.com>
Date: Wed, 12 Dec 2007 15:33:03 -0800
Local: Wed, Dec 12 2007 6:33 pm
Subject: CASE and IS NULL
I need to convert the nulls in a column to a value.

When I run the following:

SELECT
CASE
        WHEN COL1 IS NULL THEN 'UNK'
        WHEN COL1 = 'SUGAR' THEN 'SGR'
        WHEN COL1 = 'SALT' THEN 'SAL'
        WHEN COL1 = 'PEPPER' THEN 'PEP'

END AS items
FROM INV_ITEMS

It keeps returning the NULL values as NULL instead of converting them to
'UNK'.
What am I doing wrong?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SQL Menace  
View profile  
 More options Dec 12 2007, 6:47 pm
Newsgroups: microsoft.public.sqlserver.programming
From: SQL Menace <denis.g...@gmail.com>
Date: Wed, 12 Dec 2007 15:47:41 -0800 (PST)
Local: Wed, Dec 12 2007 6:47 pm
Subject: Re: CASE and IS NULL
One problem is see is that you don't have an ELSE so if a value is
'POTATO' then you will get a NULL also

WHEN COL1 = 'PEPPER' THEN 'PEP'
ELSE 'N/A' END......

Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx

On Dec 12, 6:33 pm, gracie <gra...@discussions.microsoft.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Warren Brunk  
View profile  
 More options Dec 12 2007, 6:56 pm
Newsgroups: microsoft.public.sqlserver.programming
From: "Warren Brunk" <wbr...@techintsolutions.com>
Date: Wed, 12 Dec 2007 15:56:19 -0800
Local: Wed, Dec 12 2007 6:56 pm
Subject: Re: CASE and IS NULL
Are you sure its really a null value and not just blank or something

SELECT
CASE
WHEN  COL1 IS NULL THEN 'UNK'
When  COL1 = 'NULL' THEN 'UNK'
When Col1 = '' then 'UNK'
WHEN  COL1 = 'SUGAR' THEN 'SGR'
WHEN  COL1 = 'SALT' THEN 'SAL'
WHEN  COL1 = 'PEPPER' THEN 'PEP'

END AS items
FROM esi_store_orderheader

Make sure you have all your bases covered and that the null values really
are null.

--
/*
Warren Brunk - MCITP,MCTS,MCDBA
www.techintsolutions.com
*/

"gracie" <gra...@discussions.microsoft.com> wrote in message

news:2D1C0EC2-6A78-4676-9F73-2BD00E3FFB4E@microsoft.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bruce  
View profile  
 More options Dec 12 2007, 7:14 pm
Newsgroups: microsoft.public.sqlserver.programming
From: "Bruce" <fake_dont_send@anything_.com>
Date: Wed, 12 Dec 2007 19:14:36 -0500
Local: Wed, Dec 12 2007 7:14 pm
Subject: Re: CASE and IS NULL
SELECT isnull(

CASE

COL1

WHEN 'SUGAR' THEN 'SGR'

WHEN 'SALT' THEN 'SAL'

WHEN 'PEPPER' THEN 'PEP'

END, 'UNK') AS items

FROM INV_ITEMS

"gracie" <gra...@discussions.microsoft.com> wrote in message

news:2D1C0EC2-6A78-4676-9F73-2BD00E3FFB4E@microsoft.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tibor Karaszi  
View profile  
 More options Dec 13 2007, 2:21 am
Newsgroups: microsoft.public.sqlserver.programming
From: "Tibor Karaszi" <tibor_please.no.email_kara...@hotmail.nomail.com>
Date: Thu, 13 Dec 2007 08:21:01 +0100
Local: Thurs, Dec 13 2007 2:21 am
Subject: Re: CASE and IS NULL

> Are you sure its really a null value and not just blank or something

... or perhaps the string 'NULL'

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi

"Warren Brunk" <wbr...@techintsolutions.com> wrote in message

news:6827D2F0-BCDD-4B84-9FC8-F58BEB57A714@microsoft.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »