日前遇到一个存储过程不能执行带参数的sql语句的问题,如:
select @Countint=count(id) from [@tablename] where @strwhere
总提示where 附近有错误. 后来把该句作成字符串执行:
Set @sqlstr='select @Countint=count(id) from [' +@tablename + '] where ' + @strwhere
但其中的参数@Countint就不能返回.
后来在网上查到sp_executesql可以执行sql并返回参数,其使用如下:
exec sp_executesql @sqlstr,N'@Countint int out',@Countint out
这时的@Countint 就是sql的返回值

浙公网安备 33010602011771号