I’m trying to update multiple rows in a table but due to server resources being limited I can’t do it in individual UPDATE statements. I know that this can be done in a single statement by using a CASE but I’m having trouble getting this to work as the table needs to be updated using a composite key (three columns) rather than a single value.
This example works:
UPDATE myTable
SET newValue = CASE id
WHEN 1 THEN 'val1'
WHEN 2 THEN 'val2'
WHEN 3 THEN 'val3'
END,
WHERE id IN (1,2,3)
But I need something like this to work:
UPDATE myTable
SET newValue = CASE (id,x,y)
WHEN (1,1,1) THEN 'val1'
WHEN (1,1,2) THEN 'val2'
WHEN (1,1,3) THEN 'val3'
END,
WHERE id IN (1,2,3)
Is there a way to have something like this in a single UPDATE statement or am I going to have to work around the limited server resources?
Slightly refactored from your example: