declare @JobNumber1 char(12)
set @JobNumber1 = ' 3505040'
DECLARE @OPENQUERY nvarchar(4000), @TSQL nvarchar(4000), @LinkedServer nvarchar(4000)
SET @LinkedServer = 'AS400SRV_MSDASQL'
SET @OPENQUERY = 'SELECT * FROM OPENQUERY('+ @LinkedServer + ','''
SET @TSQL = ' Call QGPL.get_eqmqty(?),' + @JobNumber1 + ')'
EXEC (@OPENQUERY+@TSQL)
Value of string:
SELECT * FROM OPENQUERY(AS400SRV_MSDASQL,' Call QGPL.get_eqmqty(?), 3505040)
Getting error:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string ' Call QGPL.get_eqmqty(?), 3505040)'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ' Call QGPL.get_eqmqty(?), 3505040)'.
declare @JobNumber1 char(12)
set @JobNumber1 = ' 3505040'
DECLARE @OPENQUERY nvarchar(4000), @TSQL nvarchar(4000), @LinkedServer nvarchar(4000)
SET @LinkedServer = 'AS400SRV_MSDASQL'
SET @OPENQUERY = 'SELECT * FROM OPENQUERY('+ @LinkedServer + ','''
SET @TSQL = ' Call QGPL.get_eqmqty(?),' + @JobNumber1 + '''' + ')'
EXEC (@OPENQUERY+@TSQL)
String value:
SELECT * FROM OPENQUERY(AS400SRV_MSDASQL,' Call QGPL.get_eqmqty(?), 3505040')
Error:
OLE DB provider "MSDASQL" for linked server "AS400SRV_MSDASQL" returned message "[IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0104 - Token , was not valid. Valid tokens: <END-OF-STATEMENT>.".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query " Call QGPL.get_eqmqty(?), 3505040" for execution against OLE DB provider "MSDASQL" for linked server "AS400SRV_MSDASQL".
It's been a couple years since I've worked much with AS400, but if memory recalls, your string should reflect the command syntax on the Client Access terminal. Does the question mark denote a parameter place holder? What happens if you try the following:
declare @JobNumber1 char(12)
set @JobNumber1 = ' 3505040'
Exec ('Call QGPL.get_eqmqty(?)', @JobNumber1) AT AS400SRV_MSDASQL
This query is not using 'OpenQuery', it calls a sp on the AS400 directly and returns result set. However, I would like to use 'OpenQuery' or 'OpenRowSet'
String value:
SELECT * FROM OPENQUERY(AS400SRV_MSDASQL,' Call QGPL.get_eqmqty 3505040')
Error:
OLE DB provider "MSDASQL" for linked server "AS400SRV_MSDASQL" returned message "[IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0104 - Token 3505040 was not valid. Valid tokens: ( INTO USING.".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query " Call QGPL.get_eqmqty 3505040" for execution against OLE DB provider "MSDASQL" for linked server "AS400SRV_MSDASQL".
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.