0

I am reading records from a linked server table, and trying to use the output in the next update statement, not on the linked server. I am assigning it to a declared variable. The file is being updated with NULL, instead of the correct check number. Any help???

Example code:

DECLARE
@Check   VARCHAR(8)
@TSQL    varchar(8000)

SELECT @TSQL = 'SELECT keyfield FROM OPENQUERY(linkedserver, 
      ''SET '+@Check+'= select keyfield from library.file WHERE document=12345)'

EXEC (@TSQL)

Update mainlibrary.file SET Keyfield2=@Check where document=12345

END
1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by kbrown123
0

Finally it worked...

SET @SQL =N'SELECT @CHECK=keyfield FROM OPENQUERY(linkedserver, 
	''select keyfield from library.table where document=' + @NEXT +''')N'
EXEC sp_executesql @sql, N'@CHECK varchar(8) OUTPUT', @CHECK OUTPUT
SELECT @CHECK
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.