Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tonyinbristol
Starting Member
3 Posts |
Posted - 2009-07-24 : 11:00:28
|
I have a simple update statement, like this:update tablename set field1 = 'W9783345' where field2 = '0206863944' and field3 = 'Active'I want to do several of these, but the only element that is the same is the field3 = 'Active' - the rest are all different. For example:update tablename set field1 = 'M1093979' where field2 = '1020506073' and field3 = 'Active'update tablename set field1 = 'W6806654' where field2 = '5243086077' and field3 = 'Active'At the moment, I have to submit each line one at a time. There MUST be a quicker and easier way of doing it. I have tried parentheses, AND statements, all kinds of ways.I am using WinSQL on data in a DB2 databaseThanks!!!Tony |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-24 : 11:16:27
|
Tryupdate tablename set field1 = case when field2 = '0206863944' then 'W9783345' when field2 = '1020506073' then 'M1093979' when field2 = '5243086077' then 'W6806654' else filed1 endwhere field3 = 'Active' MadhivananFailing to plan is Planning to fail |
|
|
tonyinbristol
Starting Member
3 Posts |
Posted - 2009-07-27 : 06:25:15
|
Many thanks madhivanan! I'll give it a go! |
|
|
tonyinbristol
Starting Member
3 Posts |
Posted - 2009-07-29 : 08:34:08
|
It works. Thanks again madhivanan! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-29 : 08:42:14
|
quote: Originally posted by tonyinbristol It works. Thanks again madhivanan!
Thanks for your feedback MadhivananFailing to plan is Planning to fail |
|
|
|
|
|