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 2005 Forums
 Transact-SQL (2005)
 replace values of null

Author  Topic 

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2008-03-04 : 12:47:55
select distinct
case when item is null then replace(item,null,'-')
else itemend
end as item
from itemstable

i want to replace all null values to '-'...but still i m getting null values..

syntax is correct still not getting results..

can anyone help?

thanks.

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-03-04 : 12:51:31
select distinct
case when item is null then '-'
else itemend
end as item
from itemstable
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-03-04 : 13:10:11
This should get you what you want:
select	coalesce(item, '-') as Item
from itemstable

...but if you still see "nulls", they are probably zero-length strings and this will convert them:
select	coalesce(nullif(item, ''), '-') as Item
from itemstable


e4 d5 xd5 Nf6
Go to Top of Page

sqlhelp14
Yak Posting Veteran

55 Posts

Posted - 2008-03-04 : 13:16:06
thanks jdaman
and blindman

got the correct results..
Go to Top of Page
   

- Advertisement -