Friday, April 13, 2018

How To Update Multiple Rows In One SQL Statement

Here's how to update multiple rows in one SQL statement using MSSQL.
UPDATE
  tblEmp
SET
  empSalary = empSrc.empSalary,
  empLevel = empSrc.empLevel
FROM
  dbo.tblEmployees AS tblEmp
  INNER JOIN
  (
    VALUES
    (001, 10000.00, 10),
    (002, 32000.00, 15),
    (003, 9500.00, 3)
  ) AS empSrc (empID, empSalary, empLevel)
    ON tblEmp.empID = empSrc.empID;
Reference: How to update multiple columns of multiple rows in one SQL statement

0 comments:

Post a Comment