0

Permanent Table Name: PermaTable1 Values: enter image description here

Question is how to execute all update commands inside the table PermaTable1?

This is my query but it does not execute the update command.

DECLARE @Query1 Nvarchar(MAX)

SET @Query1= 'SELECT Query FROM dbo.PermaTable1'

EXEC(@Query1)

Hope you can help me. Thank you.

3
DECLARE @Query1 nvarchar(max) = N'';

SELECT @Query1 += Query + N';' FROM dbo.PermaTable1;

PRINT @Query1; -- to see the first 8,192 characters

-- EXEC sys.sp_executesql @Query1; -- uncomment this when you trust it

But I have questions. Shouldn't those update queries have where clauses? Otherwise each one is going to overwrite all rows and basically undo all the updates that came before it. Also are these update commands really stored in the same table they affect?

  • Thanks for the heads up on the where clause. I was able to run the query now. Big help. Thanks again! – Byron Louise Hudkin Festin Jul 30 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.