我已成功使用类似以下内容的查询但我不能使用'变量'进行更新我可以不使用它们。这可能吗?这抱怨了
'set stuf_rec.stat =“A”
附近的语法不正确
DECLARE @stuf_no varchar(6)
set @stuf_no = 267
DECLARE @sql varchar (2000)
set @sql =
'UPDATE OPENQUERY(train,''select stat from stuf_rec
where stuf_no = '+ @stuf_no + ''')'' set stuf_rec.stat = ' + '"A"' + '
where stuf_rec.stuf_no = ' + @stuf_no + ''';'
谢谢..
答案 0 :(得分:0)
这适用于你吗?或者值是否必须有双引号?
DECLARE @stuf_no varchar(6)
set @stuf_no = '267'
DECLARE @sql varchar (2000)
set @sql =
'UPDATE OPENQUERY(train,''select stat from stuf_rec
where stuf_no = '+ @stuf_no + ''') set stuf_rec.stat = ''A''
where stuf_rec.stuf_no = ' + @stuf_no + ';'
@sql的结果如下所示:
UPDATE OPENQUERY(train,'select stat from stuf_rec
where stuf_no = 267')
set stuf_rec.stat = 'A'
where stuf_rec.stuf_no = 267;