1

I am running a query on linked server (IBM DB2) the reason I am doing this is because it takes lot of time to execute a simple query. below are the two queries, the first one runs successfully so the issue is not with the query

 select top 10 * from [AS400TS_LNK].[TEST].[AUPRDDBF].CONTACCT where  actrno = '8971'  

  select * from openquery(AS400TS_LNK, 'select * from [TEST].[AUPRDDBF].CONTACCT where  actrno = ''8971''')

and the error I get while running the open query

OLE DB provider "DB2OLEDB" for linked server "AS400TS_LNK" returned message "Token *N was not valid. Valid tokens: *N. SQLSTATE: 42601, SQLCODE: -104".

Msg 7321, Level 16, State 2, Line 1

An error occurred while preparing the query "select * from [AS400TS_LNK].[TEST].[AUPRDDBF].CONTACCT where actrno = '8971'" for execution against OLE DB provider "DB2OLEDB" for linked server "AS400TS_LNK".

2
  • 1
    Just a wild guess here, but easy to test. Try removing the square brackets from the openquery statement... Commented Oct 13, 2017 at 6:29
  • As @user1429080 mentioned, using square brackets to quote identifiers is a SQL Server thing; send standard SQL to the remote server, using double quotes for identifiers when necessary (which is not the case here anyway). Commented Oct 13, 2017 at 12:36

1 Answer 1

1

Try this:

select * 
from openquery(AS400TS_LNK, 'select * from TEST.AUPRDDBF.CONTACCT where actrno = ''8971''')

Or, failing that, try this:

select * 
from openquery(AS400TS_LNK, 'select * from TEST.AUPRDDBF.CONTACCT') 
where actrno = '8971'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.