Solved

How do I do a multiple UPDATE ... WHERE ... ?

Posted on 2007-11-20
3
178 Views
Last Modified: 2010-04-21
Question:

Is there a more efficient way to write this simple UPDATE query:

update Table1
set Field1 = 'String1' where Field2 = 'Value1';
update Table1
set Field1 = 'String2' where Field2 = 'Value2';
...
update Table1
set Field1 = 'StringN' where Field2 = 'ValueN'; ?

0
Comment
Question by:masbe
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
not "simple", but single statement is possible:

update Table1
set Field1 = case field2
  when 'Value1' then 'String1' 
  when 'Value2' then 'String2' 
  ...
  when 'ValueN' then 'StringN' 
end
where Field2 IN ( 'Value1', 'Value2', ... 'ValueN' )
;

Open in new window

0
 
LVL 23

Expert Comment

by:Ashish Patel
Comment Utility
You have to write multiple statements for this. No other way round.
or if the where clause and value to be set have something common then do like this
update Table1
set Field1 = Replace(Field2, 'Value', 'String')
0
 

Author Closing Comment

by:masbe
Comment Utility
Worked fine. Thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now