Question

I have successfully dont a query using something like the following but I can't do an update with 'variables' I can without them. Is this possible? This complains that

'Incorrect syntax near ' 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 + ''';'

Thanks..

No correct solution

OTHER TIPS

Does this work for ya? Or does the value have to have the double quotes?

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 + ';' 

The result of @sql looks like the following:

UPDATE OPENQUERY(train,'select stat from stuf_rec      
                        where stuf_no =  267') 
    set stuf_rec.stat = 'A'       
    where stuf_rec.stuf_no = 267;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top