I am trying to achieve a single update statement that would achieve the same results as below. Right now I compile this in php where there are 700+ statements created. There has to be somehow I can update all of the records with their values where the id matches in just one statement.
UPDATE `table` SET `val1` = 1, `val2` = 2, `val3` = 3 WHERE `id` = 1;
UPDATE `table` SET `val1` = 4, `val2` = 5, `val3` = 6 WHERE `id` = 2;
UPDATE `table` SET `val1` = 7, `val2` = 8, `val3` = 9 WHERE `id` = 3;
etc...
Something like this on the microsoft site looks about what I am looking for but seems like it would be very robust
UPDATE dbo.DimEmployee
SET VacationHours =
( CASE
WHEN ((VacationHours - 10.00) < 0) THEN VacationHours + 40
ELSE (VacationHours + 20.00)
END
)
WHERE SalariedFlag = 0;
and I would need it to be more like below which Im not sure if it is doable.
UPDATE 'table'
SET val1,val2,val2 =
(CASE
WHEN (id = 1) THEN val1 = 1, val2 = 2, val3 = 3,
WHEN (id = 2) THEN val1 = 4, val2 = 5, val3 = 6,
WHEN (id = 3) THEN val1 = 7, val2 = 8, val3 = 9
ELSE // do nothing
END
)