I have a stored procedure build update query and store in temp table each time in loop.
Total query built UNKNOWN (2 to 4)
How can I put multi query in a transaction?
For example, temp table contains following rows in column EXPSQL (nvarchar)
id EXPSQL
1 Update tableA SET Name = 'Test' WHERE id=1
2 Update tableB SET Name = 'Test2' WHERE id=10
How can I begin a transaction for a loop to exec above query? or is there any other way?
while @id < total
begin
set @id = @id +1
select @SQL = EXPSQL FROM #TEMPTABLE WHERE id=@id
EXEC (@SQL)
end
Thanks
If you want to execute all as one:
If you want to execute each one individually: