篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL动态SQL相关的知识,希望对你有一定的参考价值。
-- Simple Execution
EXEC ('SELECT Top 1 * FROM [Person].[Person]')
-- sp_executeSQL
EXECUTE sp_executesql
N'SELECT *
FROM [AdventureWorks2014].HumanResources.Employee
WHERE BusinessEntityID = @level',
N'@level tinyint',
@level = 20
WITH RECOMPILE -- <<-- Optional
-- With recompile :
-- Throw away the existing query plan
-- and build another one