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 |
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 = nullAnd 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 0And 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 NULLThe second one works because the empty string is implicitly converted to an INT data type, which becomes 0.SQL Server Helperhttp://www.sql-server-helper.com |
 |
|
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 NULLThe second one works because the empty string is implicitly converted to an INT data type, which becomes 0.SQL Server Helperhttp://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. |
 |
|
|
|
|