SQL syntax: update multiple fields in the same table with different conditions

is there a way to combine these statements?

update table set field1 = 0 where field1 is NULL
update table set field2 = 0 where field2 is NULL


field1 and field2 are in the same table.  however, there are instances where field1 may be NULL but field2 is not NULL (or vice versa), and i don't want to update field1 to zero when field2 is NULL.

thanks
LVL 44
zephyr_hex (Megan)DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dqmqConnect With a Mentor Commented:
update table
 set field1 = isnull(field1,0)
, field2 = isnull(field2,0)
0
 
lluddenConnect With a Mentor Commented:
Update Mytable SET Field1 = CASE WHEN Field1 IS NULL THEN 0 ELSE Field1 END
Field2 - CASE WHEN Field2 IS NULL THEN 0 ELSE Field2 END
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.