Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Case Statements

Author  Topic 

kathyc2003
Starting Member

15 Posts

Posted - 2006-12-04 : 16:14:23
Hello

I have written a case statement and it does the exact opposite of what I want it to do.

If the field New_sales_initiative is NULL, it puts in a value
of 'I AM NOT NULL' and vice versa.
What have I done wrong?


SELECT
createdbyname,
New_sales_initiative,
leadsourcecodename,

CASE New_sales_initiative
WHEN NULL
THEN
'I AM NULL'
ELSE
'I AM NOT NULL'

END AS impied_sales_initiative

FROM dbo.FilteredLead

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-04 : 16:20:39
[code]SELECT
createdbyname,
New_sales_initiative,
leadsourcecodename,

CASE
WHEN New_sales_initiative IS NULL
THEN
'I AM NULL'
ELSE
'I AM NOT NULL'
END AS impied_sales_initiative

FROM dbo.FilteredLead[/code]
Also, check out the ISNULL and COALESCE functions for checking for NULLs.
Go to Top of Page

kadams21
Starting Member

3 Posts

Posted - 2006-12-04 : 16:24:04
Give this a shot...
SELECT
createdbyname,
New_sales_initiative,
leadsourcecodename,
impied_sales_initiative =
CASE WHEN New_sales_initiative IS NULL THEN 'I AM NULL' ELSE 'I AM NOT NULL' END
FROM dbo.FilteredLead
Go to Top of Page
   

- Advertisement -