Link to home
Start Free TrialLog in
Avatar of ccleebelt
ccleebeltFlag for United States of America

asked on

Updating multiple columns in a single update transaction

I have a table with many columns.  Some have a default value of 0 and need to set it to null (after removing the constraint of course).

Rather than have multiple update statements that look like this:

update table1 set column1 = null where column1 = 0
update table1 set column2 = null where column2 = 0

Is there a way to wrap these up into a single update statement or transaction with multiple where clauses?
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

update table1 set
  column1 = case when column1 = 0 then null else column1 end
  , column2 = case when column2 = 0 then null else column2 end
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial