在SQL查询跟踪器里跟踪.NET执行SQL的过程,对于传递参数的情况,SQLServer将传递的参数转化为动态SQL嵌入参数的方式,如
EXECUTE sp_executesql
N'SELECT * FROM AdventureWorks.HumanResources.Employee
WHERE ManagerID = @level',
N'@level tinyint',
@level = 109;
'select @user = count(distinct userid) from '+@moTable --为变量赋值--执行@sql中的语句
EXEC sp_executesql
N'SELECT @EmployeeCount=COUNT(*) FROM AdventureWorks.HumanResources.Employee' ,
N'@EmployeeCount tinyint out',
@EmployeeCount out
注意:不要在动态SQL语句里写入%等通配符,而应作为参数的一部分传入。
EXECUTE sp_executesql
N'SELECT * FROM AdventureWorks.HumanResources.Employee
WHERE ManagerID = @level',
N'@level tinyint',
@level = 109;
'select @user = count(distinct userid) from '+@moTable --为变量赋值--执行@sql中的语句
EXEC sp_executesql
N'SELECT @EmployeeCount=COUNT(*) FROM AdventureWorks.HumanResources.Employee' ,
N'@EmployeeCount tinyint out',
@EmployeeCount out
注意:不要在动态SQL语句里写入%等通配符,而应作为参数的一部分传入。