DB2 query problems

Posted on 2006-04-03
Last Modified: 2008-01-09
I am trying to run a query against our AS/400 DB2 database and get the following error

Additional information: SQL0104: Token = was not valid. Valid tokens: ON LEFT CROSS INNER RIGHT EXCEPTION.
Cause . . . . . :   A syntax error was detected at token =.  Token = is not a valid token.  A partial list of valid tokens is ON LEFT CROSS INNER RIGHT EXCEPTION.  This list assumes that the statement is correct up to the token.  The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery  . . . :   Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token =. Correct the statement.  The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause.

...for the following query-

SELECT aalgtx.ahoaa, aaaatx.ahoaa, ijhpcd.abrij, aabfcd.ahoaa, dfe3tx.acudf, anjcnb.acuan, ijabnb.abrij
FROM aqhprd.acuan, aqhprd.abrij, aqhprd.ahoaa, aqhprd.acudf
INNER JOIN ana7cd.acuan=ija7cd.abrij and
anabnb.acuan=ijabnb.abrij and
anbvnb.acuan=ijbvnb.abrij and
ijabnb.abrij=aaabnb.ahoaa and
WHERE anjcnb = 12345678

...any idea where I am wrong?
Question by:jimtxas
    LVL 4

    Expert Comment

    Suspect it should be INNER JOIN something WHERE ana7cd.acuan=ija7cd.abrij and ...

    What's the 'something where'?
    LVL 4

    Expert Comment

    That, of course, does not address the possible FROM aqhprd.acuan, ... issues.
    LVL 65

    Accepted Solution

    try rewriting using just the WHERE clause i.e. no INNER JOIN

    WHERE  ana7cd.acuan=ija7cd.abrij
    AND anabnb.acuan=ijabnb.abrij
    AND anbvnb.acuan=ijbvnb.abrij
    AND ijabnb.abrij=aaabnb.ahoaa
    AND aabfcd.ahoaa=dfapcd.acudf
    AND anjcnb = 12345678

    What happens

    Author Comment

    I've made some progress-  still same error but found other issues that I have corrected-

    Here's the full query now-

            sql = "SELECT c.aalgtx, c.aaaatx, b.ijhpcd, c.aabfcd, d.dfe3tx, a.anjcnb, b.ijabnb " & _
           "FROM aqhprd.acuan a " & _
           "JOIN aqhprd.abrij b, aqhprd.ahoaa c, aqhprd.acudf d on (a.ana7cd = b.ija7cd) and " & _
                       "(a.anabnb = b.ijabnb) and " & _
                       "(a.anbvnb = b.ijbvnb) and " & _
                       "(b.ijabnb = c.aaabnb) and " & _
                       "(c.aabfcd = d.dfapcd) " & _
                       "WHERE (a.anjcnb = " & RegKey & ""

    I also made the following join work successfully, but I need to build it out similar to above, but the following works-

             sql = "SELECT  b.ijhpcd,  a.anjcnb, b.ijabnb " & _
            "FROM aqhprd.acuan a " & _
            "inner JOIN aqhprd.abrij b on a.ana7cd = b.ija7cd " & _
                        "WHERE a.anjcnb = " & RegKey & ""

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction If you are not already aware of what you could use a table with sequential integer values for in SQL, you can read Delimited String Parsing in SQL Server 2005 or later ( by BrandonGalderisi (h…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now