Skip to content
Advertisement

SQL execute return of select

I have select

Im droping getdate defaults and want bind one getdate default. Result of this has 2 lines

and i want to execute it in one command. Any ideas?

Advertisement

Answer

You won’t be able to dynamically generate the SQL and execute it in a single set based query. You’ll have to iterate through the results of your select – either in a CURSOR or WHILE loop – and build the generated statement into a variable and then execute that with EXEC or sp_executesql; e.g.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement