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)
 update field where null

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2007-03-08 : 12:33:02
Why won't this work?

Update myTbl set myFld = 0 where myFld = null

And this says a number of rows were effected:

Update myTbl set myFld = 0 where myFld = ''

I'm guessing the latter picks up the ones that are already 0

And myFld type is INT.


Thanks,

Zath

sshelper
Posting Yak Master

216 Posts

Posted - 2007-03-08 : 12:44:18
You have to use the ISNULL function:

UPDATE myTbl SET myFld = 0 WHERE myFld IS NULL

The second one works because the empty string is implicitly converted to an INT data type, which becomes 0.

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-08 : 13:12:09
quote:
Originally posted by sshelper

You have to use the ISNULL function:

UPDATE myTbl SET myFld = 0 WHERE myFld IS NULL

The second one works because the empty string is implicitly converted to an INT data type, which becomes 0.

SQL Server Helper
http://www.sql-server-helper.com


Just to clarify - that is the right way to do it, but it's using the IS NULL operator, not the ISNULL function, which is something completely different.
Go to Top of Page
   

- Advertisement -