信息交流、传播、提炼

nice to meet you

博客园 首页 新随笔 联系 订阅 管理
在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语句里写入%等通配符,而应作为参数的一部分传入。
posted on 2009-01-17 23:53  seeyou  阅读(381)  评论(0)    收藏  举报