This is a really strange one. Take the following SQL... declare @tmp TABLE (id int IDENTITY(1,1), username nvarchar(50) NOT NULL, age int NOT NULL)insert into @tmp (username, age) select 'David', 30 union allselect 'Bob', 25 union allselect 'Mikey', 50 union allselect 'Laura', 45 union allselect 'Pedro', 60select * from @tmp update @tmp set age=50 where id=4update @tmp set age=35 where id=1update @tmp set age=21 where id=5select * from @tmp
Is it possible to replace the multiple UPDATE statements with one single statement? For example, if I had the relevant ID row values I need to update, plus the new age values like so...declare @newAges TABLE (idToUpdate int, age int NOT NULL)insert into @newAges (idToUpdate, age) select 4, 50 union allselect 1, 35 union allselect 5, 21select * from @newAges
Can the UPDATE be performed by selecting from the second table variable, therefore achieving the update in a single operation?