Update bulk data in second table's one column based upon first table's another column's data which has multiple condition MSSQL

bikashgosai

bikashgosai

Posted on April 4, 2023

Update bulk data in second table's one column based upon first table's another column's data which has multiple condition MSSQL
UPDATE table2
SET column2 = 
  CASE 
    WHEN table1.column1 = 'condition 1' THEN 'new value 1'
    WHEN table1.column1 = 'condition 2' THEN 'new value 2'
    WHEN table1.column1 = 'condition 3' THEN 'new value 3'
    ELSE table2.column2
  END
FROM table2 
JOIN table1 ON table2.some_column = table1.some_column
Enter fullscreen mode Exit fullscreen mode
πŸ’– πŸ’ͺ πŸ™… 🚩
bikashgosai
bikashgosai

Posted on April 4, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related