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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Question on UPDATE statement

Author  Topic 

fliu032
Starting Member

2 Posts

Posted - 2004-10-13 : 07:55:18
Dear All:
i got a problem with UPDATE statement.
see if i hv a table has two column first is ID second is Val.
for some reason, i need to update three rows in this table, for example, first row with ID = 1 , second ID = 2 and third ID = 3. i want to update the Val for this three row, for first row update Val to 2, second row update Val to 3 and third row update Val to 6.
i know if i use three update statement to do it , will be very easy.
But, is there any way, i just use only one UPDATE statement to update those three rows?
Plz help!!!!
Thx!!

hgorijal
Constraint Violating Yak Guru

277 Posts

Posted - 2004-10-13 : 08:12:47
how did you arrive at the new values 2, 3 and 6. Are they just random or hold any mathematical/logical formula.

Hemanth Gorijala
BI Architect / DBA...

Exchange a Dollar, we still have ONE each.
Exchange an Idea, we have TWO each.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-10-13 : 12:30:52
something like this?

update MyTable
set val = case when id = 1 then 1 when id = 2 then 2 when id = 3 then 6 else val end
where id in (1,2,3)

Go with the flow & have fun! Else fight the flow
Go to Top of Page

fliu032
Starting Member

2 Posts

Posted - 2004-10-13 : 22:22:39
Spirit1 Thx very very very very much!!!!!!!~~~~~~~~~~ i hv stucked on this problem for a loooooooooooooooong long time~~~~!
Go to Top of Page
   

- Advertisement -