Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run this query:

                       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.

share|improve this question
Don't you need to put the a% in single quotation marks? such as 'a%'. In your case, you may have to use it double, as in ` ... AND MBCUNO LIKE ''a%'' ' )' ` – RoKa Apr 10 '13 at 9:13
I DO IT 'A%' , ''a%'' BUT GET SAME ERROR – A.elm5zngy Apr 10 '13 at 9:45
Can you confirm that on the linked server, the domain name is specified in the Security settings for the remote login? The linked server must be set to "Be made using this security context" with a specific remote domain\login and password. – RoKa Apr 10 '13 at 9:51
it's Ok , I make the Same Query without " AND MBCUNO LIKE ''a%'' ' ) " and return result . – A.elm5zngy Apr 10 '13 at 10:24
This might sound like a silly idea, but did you try swopping the where clause around? Such as : SELECT * FROM OPENQUERY([XXX], 'SELECT * FROM Database.Table WHERE MBCUNO LIKE ''a%'' and (MBCONO=650)' ) – RoKa Apr 10 '13 at 10:35
up vote 2 down vote accepted

I would suggest you change your original SQL Statement as follows:

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.