Hi,
Your code is wrong regarding the number of quotation marks, which you use.
You should always PRINT the query and check how it is looks like when using dynamic query.
if you will try to run the following code (printing your query), then you will see what query is actually pass to the server and you will notice that it is wrong
DECLARE @TSQL varchar(8000),
@VAR NVARCHAR(20)
SELECT @VAR = '500205728'
SELECT @TSQL = 'SELECT * FROM OPENQUERY(BDTEST,''SELECT * FROM DEL d WHERE d.DCC = ''''' + @VAR + ''''''')'
PRINT (@TSQL)
The result is this test which is not well formatted SQL :
SELECT * FROM OPENQUERY(BDTEST,'SELECT * FROM DEL d WHERE d.DCC = ''500205728''')
Try to use this:
SELECT @TSQL = 'SELECT * FROM OPENQUERY(BDTEST,''SELECT * FROM DEL d WHERE d.DCC = ' + @VAR + ''')'
Fix your quotation marks and you should get the expected result set probably