We help IT Professionals succeed at work.

SQL: Want to update multiple rows in one statement

renisenbb
renisenbb asked
on
Let's say i have 3 rows:
id    year
--    --------
10    1980
11     1981
12     1992
I want to update these rows so that it is :
10    1970
11     1901
12     1980
So i want to update ids 10,11,12 with the year 1970,1901,1980   RESPECTIVELY.
How would i do this in DB2?
Comment
Watch Question

Naitik GamitSoftware Developer
Top Expert 2015

Commented:
try like,

Update Year_Master(your table) set year=
 case
     when id = 10 then 1970
     when id = 11 then 1901
     when id = 12 then 1980
  end
     WHERE id  in (10,11,12)
Thanks, that worked. What if the second row update was not successful, will that roll back the update for the first row?
Naitik GamitSoftware Developer
Top Expert 2015

Commented:
No.

Author

Commented:
It worked.