Solved

Updating multiple columns in a single update transaction

Posted on 2013-12-10
2
261 Views
Last Modified: 2013-12-10
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?
0
Comment
Question by:ccleebelt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 39710310
update table1 set
  column1 = case when column1 = 0 then null else column1 end
  , column2 = case when column2 = 0 then null else column2 end
0
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 39710548
I would perhaps add a WHERE clause to restrict the number of scanned rows, like this:
update table1 set
  column1 = case when column1 = 0 then null else column1 end
  , column2 = case when column2 = 0 then null else column2 end 
WHERE column1 = 0 OR column2 = 0

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question