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.
Author |
Topic |
Pete_N
Posting Yak Master
181 Posts |
Posted - 2012-01-06 : 11:27:34
|
I am trying to do a case statement as followsSelect Case DestSortCodeWHEN NULL then 0 else 1 end as destsortcodeFROM [dbo].[Mytable]DestSortCode is a NULL but select query is returning 1Select DestSortCodeFROM [dbo].[MyTable]Select query returns NULL |
|
latch
Yak Posting Veteran
62 Posts |
Posted - 2012-01-06 : 11:44:22
|
I think instead of using Case statement you can use ISNULL function : "select isnull(DestSortCode,0) from [dbo].[Mytable]" |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Pete_N
Posting Yak Master
181 Posts |
Posted - 2012-01-06 : 11:52:46
|
quote: Originally posted by latch I think instead of using Case statement you can use ISNULL function : "select isnull(DestSortCode,0) from [dbo].[Mytable]"
Hi I am using this query in an execute SQL tak in a SSIS and need to return 0 if the DestSortCode in a NULL and a 1 if it isnt |
 |
|
Pete_N
Posting Yak Master
181 Posts |
Posted - 2012-01-06 : 12:00:56
|
quote: Originally posted by Pete_N
quote: Originally posted by latch I think instead of using Case statement you can use ISNULL function : "select isnull(DestSortCode,0) from [dbo].[Mytable]"
Hi I am using this query in an execute SQL tak in a SSIS and need to return 0 if the DestSortCode in a NULL and a 1 if it isnt
SortedSelect CASE ISNULL(DestSortCode, 0) WHEN 0 then 0 else 1 endFROM [dbo].[MyTable] |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2012-01-06 : 16:53:58
|
I think that your CASE is not returning the hoped for results because of the syntax used. In essence, you are asking if DestSortCode = NULL when you are trying to ask if DestSortCode IS NULL. If you use a slightly different syntax, you'll be asking the right question:[CODE]Select Case WHEN DestSortCode IS NULL then 0 else 1 end as destsortcodeFROM [dbo].[Mytable][/CODE]HTH=================================================Men shout to avoid listening to one another. -Miguel de Unamuno |
 |
|
|
|
|