You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Dynamic SQL is executable with the EXEC / EXECUTE statement. It takes one string parameter.
Example:
declare @tableName as varchar
set @tableName = 'Orders'
execute ('select * from [' + @tableName +']')
You can also execute dynamic SQL with the built in sp_executesql store procedure. This can take multiple parameters. The first parameter is the dynamic SQL statement. The next N are variable definitions for the dynamic SQL, and the next N are the values for variables.
Example:
exec sp_executesql 'select * from orders where orderid=@orderid' , '@orderid int' , 10248
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="dd25274f-68f6-4e0b-84a6-4a955b4a10e3"><ac:parameter ac:name="">_Toc57371241</ac:parameter></ac:structured-macro>

  • No labels