sp_executesql 求助!

asdf13225 asdf13225 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

ALTER proc [dbo].[Proc_Decide_Field]
/** 判断表中是否存在某字段 **/
( @xTable Nvarchar(20),
@xField Nvarchar(20),
@M smallint output)
AS

Begin
declare @Sql as varchar(max)
set @Sql='
if exists(select * from PREVIOUS_FILE..syscolumns where id=object_id('+
'''PREVIOUS_FILE.dbo.'+@xTable+''''+') and Name='+''''+@xField+''''+')
set @M=1
else
set @M=0'

print @Sql
exec sp_executesql @Sql,N'@M int out',@M out
print @M
end

例
declare @K int
exec proc_decide_field '十二月','班级',@K output
结果显示:

if exists(select * from PREVIOUS_FILE..syscolumns where id=object_id('PREVIOUS_FILE.dbo.十二月') and Name='班级')
set @M=1
else
set @M=0
消息 214,级别 16,状态 2,过程 sp_executesql,第 1 行
过程需要类型为 'ntext/nchar/nvarchar' 的参数 '@statement'。
...全文
评论 5
收藏 已收藏
分享
返回顶部
asdf13225
疑难问题 22,298 成员 121,727 内容