EXECUTE ( string )
dynamic SQL in its own batch scope
What changes
- Input
- string variable or literal
- Output or change
- whatever the dynamic batch does
Syntax at a glance
EXEC ( { @string_variable | N'tsql_string' } [ + ...n ] )
Work example
A legacy batch builds dynamic SQL and needs an injection-safe replacement path.
Keep statement text fixed and pass values through typed parameters with sp_executesql. Never concatenate user input into executable text.
Check your work EXECUTE ( string ). Changing a value changes only a parameter value and cannot add a new SQL statement.
Open Microsoft Learn for full syntax, permissions, and details for your version.