debugsqlMinor
Getting error when trying to use OPENQUERY Msg 7321, Level 16, State 2, Line 1
Viewed 0 times
errormsglineleveltryinggettingopenquery7321statewhen
Problem
When I run this query:
I get the error:
OLE DB provider "DB2OLEDB" for linked server "XXX" returned message
"Token %ŸFOR SKIP WITH FETCH ORDER UNION EXCEPT OPTIMIZE SQLSTATE:
42601, SQLCODE: -104".
Msg 7321, Level 16, State 2, Line 1 An error
occurred while preparing the query "SELECT * FROM Database.Table WHERE
(MBCONO=650) AND MBCUNO LIKE a%'" for execution against OLE DB
provider "DB2OLEDB" for linked server "LAWSON".
I can run the same query without
SELECT *
FROM OPENQUERY([XXX], 'SELECT *
FROM Database.Table
WHERE (MBCONO=650) AND MBCUNO LIKE a%' )I get the error:
OLE DB provider "DB2OLEDB" for linked server "XXX" returned message
"Token %ŸFOR SKIP WITH FETCH ORDER UNION EXCEPT OPTIMIZE SQLSTATE:
42601, SQLCODE: -104".
Msg 7321, Level 16, State 2, Line 1 An error
occurred while preparing the query "SELECT * FROM Database.Table WHERE
(MBCONO=650) AND MBCUNO LIKE a%'" for execution against OLE DB
provider "DB2OLEDB" for linked server "LAWSON".
I can run the same query without
AND MBCUNO LIKE a% successfully.Solution
I would suggest you change your original SQL Statement as follows:
This has the two variable swopped around, and the
Ensure that all your table & column references are correct
SELECT *
FROM OPENQUERY([XXX], 'SELECT * FROM database.table where left(MBCUNO, 1) = ''a'' and (MBCONO=650) ' )This has the two variable swopped around, and the
like % exchanged for a left(mbcuno,1). Ensure that all your table & column references are correct
Code Snippets
SELECT *
FROM OPENQUERY([XXX], 'SELECT * FROM database.table where left(MBCUNO, 1) = ''a'' and (MBCONO=650) ' )Context
StackExchange Database Administrators Q#39621, answer score: 3
Revisions (0)
No revisions yet.