SqlServer中用exec处理sql字符串中含有变量的小例子

SqlServer中,用exec处理sql字符串中含有变量,提示:必须声明标量变量@(已解决!)

复制代码 代码如下:

declare @tssj nvarchar(100)  — 外部变量
declare @Sql_Sql nvarchar(100) — 存sql字符串变量

      set @Sql_Sql =N’select @tssj=jpk from b where bzmc=”中国”’

EXEC sp_executesql @Sql_Sql,N’@tssj int output’,@tssj output
select @tssj  


N’@tssj int output’,@tssj output
这句是关键,是传入变量参数和传出变量参数!

原创文章,作者:bd101bd101,如若转载,请注明出处:https://blog.ytso.com/234655.html

(0)
上一篇 2022年1月23日
下一篇 2022年1月23日

相关推荐

发表回复

登录后才能评论