0

我已经成功地不使用类似下面的东西进行查询,但我无法使用“变量”进行更新,而没有它们我可以。这可能吗?这抱怨

'附近的语法不正确' 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 + ''';'

谢谢..

4

1 回答 1

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;
于 2012-07-03T11:33:16.230 回答