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
is that the problem is that the query that I shared works PERFECT in SQL, however in Reporting Services is where I have the problem
Hi @Marco Chavez
We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.
Hi @Marco Chavez
We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.
Sign in to comment