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
 SQL Server Development (2000)
 conver zero length string to null

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2006-11-03 : 10:06:11
How can I conver zero length string(" ") to null?

nr
SQLTeam MVY

12543 Posts

Posted - 2006-11-03 : 10:10:10
Where is the zero length string?

update tbl
set fld = null
where fld = ''



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-11-03 : 10:12:02
select nullif(fld, '')



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-11-03 : 12:11:49
" " is not a zero length string
"" is a zero length string

Jay White
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-03 : 13:02:59
Try SELECT LEN(' ')


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-11-03 : 13:26:18
Holy shit.

declare @v varchar(10)
select @v = ' '
select nullif(@v, '')

 
Thanks for pointing that out ...

Jay White
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-03 : 13:33:05
"Holy shit."

It gets worse ....

declare @v varchar(10)
select @v = ' ' -- 10 spaces ...
SELECT LEN(@v), DATALENGTH(@v)
select nullif(@v, '')

on this basis we decided that we would not hold "empty strings" and would stores NULLs instead ...

Kristen
Go to Top of Page
   

- Advertisement -