Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update multiple rows having diff condition in one go 1

Status
Not open for further replies.

Zoom1234

Programmer
Oct 30, 2003
116
BE
Hello,

I have to do update operation to the set of records
e.g.
Code:
update tablename set value=100 where id=1;
update tablename set value=200 where id=2;
update tablename set value=300 where id=3;
update tablename set value=400 where id=4;

I tried pasting all the statements in query browser but only one statement gets executed. How can I update this bunch of records in one go.

Thanks.
 
Hi

Personally I recommend using your multiple [tt]update[/tt] statements. Will be easier to read/debug/modify them later.
Code:
[b]update[/b] tablename
[b]set[/b] value[teal]=[/teal]case id
  when [purple]1[/purple] then [purple]100[/purple]
  when [purple]2[/purple] then [purple]200[/purple]
  when [purple]3[/purple] then [purple]300[/purple]
  when [purple]4[/purple] then [purple]400[/purple]
end
[b]where[/b] id [b]in[/b] [teal]([/teal][purple]1[/purple][teal],[/teal][purple]2[/purple][teal],[/teal][purple]3[/purple][teal],[/teal][purple]4[/purple][teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top