ccleebelt
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
column1 = case when column1 = 0 then null else column1 end
, column2 = case when column2 = 0 then null else column2 end