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 |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-15 : 03:29:36
|
| i have an update statemetn where i update one table based on another UPDATE t1SETt1.number=ISNULL(vwt1access.number,t1.number),t1.name=ISNULL(vwt1access.naeme,t1.name),t1.smsreceipt=ISNULL(vwt1access.smsreceipt,t1.smsreceipt),t1.[datetime]=getdate()FROMvwt1accesswhat do i need to change if I want it to update the field only if the new field is not blank or null ?? (meaning if it's blank I want to keep the old data) - now it blanks it |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-15 : 03:55:26
|
| [code]t1.name=ISNULL(NullIf(vwt1access.name, ''),t1.name),[/code] |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-15 : 03:57:29
|
| thanks kristen this will also not update any blanks in additional to null? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-15 : 04:00:33
|
| Yup |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-15 : 08:04:20
|
quote: Originally posted by esthera i have an update statemetn where i update one table based on another UPDATE t1SETt1.number=ISNULL(vwt1access.number,t1.number),t1.name=ISNULL(vwt1access.naeme,t1.name),t1.smsreceipt=ISNULL(vwt1access.smsreceipt,t1.smsreceipt),t1.[datetime]=getdate()FROMvwt1accesswhat do i need to change if I want it to update the field only if the new field is not blank or null ?? (meaning if it's blank I want to keep the old data) - now it blanks it
whats t1? is this the full query? I also cant spot any relationships between tables------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-15 : 08:47:38
|
Yeah, typos in column names too, I figured it was just a "sample example" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-15 : 08:48:58
|
quote: Originally posted by Kristen Yeah, typos in column names too, I figured it was just a "sample example" 
Me too hoping so otherwise posted code does not make any sense at all ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|