This error occurs when you mix the join syntax styles.
SELECT * FROM LIB1/TABLE1 A, LIB1/TABLE2 B LEFT OUTER JOIN LIB1/TABLE3 C ON A.FIELD1 = C.FIELD1
The solution is to replace the commas with ?cross join?
SELECT * FROM LIB1/TABLE1 A CROSS JOIN LIB1/TABLE2 B LEFT OUTER JOIN LIB1/TABLE3 C ON A.FIELD1 = C.FIELD1
Source: V6R1 Memo to users
Resolving a SQL0338 failure In V6R1, a query might fail with SQL0338 for queries with a JOIN. In earlier releases, this usage was allowed. The error needs to be issued because of the implied order of the join condition. To resolve the SQL0338 failure, add parentheses to the query to remove the ambiguity.
Select a.c1 From BASE1 a LEFT OUTER JOIN BASE3 c LEFT OUTER JOIN BASE2 b on a.c1 = b.c1) on b.c1n = c.c1n
is equivalent to
Select a.c1 From BASE1 a LEFT OUTER JOIN (BASE3 c LEFT OUTER JOIN BASE2 b on a.c1 = b.c1) on b.c1n = c.c1n
SQL0338 can also be issued when a table is specified followed by a comma and a joined table.
Select a.c1 From BASE1 a, BASE2 b INNER JOIN BASE3 c on a.c1 = c.c1
is equivalent to
Select a.c1 From BASE1 a, (BASE2 b INNER JOIN BASE3 c on a.c1 = c.c1)
To specify a.c1 in the ON clause for the joined table, include the first table within the joined table.
Select a.c1 From BASE1 a CROSS JOIN BASE2 b INNER JOIN BASE3 c on a.c1 = c.c1


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: December 10, 2016