Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1729
  • Last Modified:

DB2 query problems

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?
  • 2
1 Solution
Suspect it should be INNER JOIN something WHERE ana7cd.acuan=ija7cd.abrij and ...

What's the 'something where'?
That, of course, does not address the possible FROM aqhprd.acuan, ... issues.
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
jimtxasAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now