-1

I want to update multiple attributes of same field in SQL. How can I write a single query to perform this task in SQL?

I am attaching the picture for assistance to this question. Please suggest me one line query to perform this task, i.e. to update all number from '111' to '555' and '222' to '999' with single line SQL Query.

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Please share your current approach with the community so we can help you fix your current query – j.rmz87 Sep 10 '21 at 04:02
  • Does this answer your question? [SQL - Update multiple records in one query](https://stackoverflow.com/questions/20255138/sql-update-multiple-records-in-one-query) – kplus Sep 12 '21 at 07:47

2 Answers2

0

You may use a single update with the help of a CASE expression:

UPDATE yourTable
SET NUMBER = CASE NUMBER WHEN '111' THEN '555'
                         WHEN '222' THEN '999' END
WHERE NUMBER IN ('111', '222');
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can try this:

update table
set column = case when column = 111 then 555
              when column =  222 then 999
         end
where column in (111,222); 
Zubair Ahmed
  • 23
  • 2
  • 8