title: SQL Error [42972]: [SQL0338] JOIN predicate or MERGE ON clause not valid
body: <blockquote>
  <p>SQL Error [42972]: [SQL0338] JOIN predicate or MERGE ON clause not valid.</p>
  </blockquote>
  <p>I'm trying to run the query below, but an error occurs in the JOIN in the table DB170P. Can you help me?</p>
  <pre><code>SELECT ACBAC AS &quot;CBUYER&quot;
  ,      HBAC AS &quot;BORDER&quot;
  ,      IHTRCD AS &quot;TRANS&quot;
  ,      IHRVCD AS &quot;REV&quot;
  ,      DATE(CONCAT(CONCAT(CONCAT(CONCAT(IHTRMM,'/'),IHTRDD),'/'),IHTRCC*100+IHTRYY)) AS &quot;RECD&quot;
  ,      VADFCD AS &quot;DF&quot;
  ,      HVEND  AS &quot;VENC&quot;
  ,      VSNAME AS &quot;VNAME&quot;
  ,      IHSRNO AS &quot;SER&quot;
  ,      DATE(PHCUMM||'/'||PHCUDD||'/'||(PHCUCC*100+PHCUYY)) &quot;CUST_DATE&quot;
  ,      PHBLNO AS &quot;B/L&quot;
  ,      IHPLST AS &quot;NF&quot;
  ,      IHORNO AS &quot;PO&quot;
  ,      IHPNO  AS &quot;PN&quot;
  ,      MODEL
  ,      (CASE WHEN CONCAT(IHTRCD, IHRVCD) IN('D20','D50T','D50Y','E30') THEN IHQTY ELSE -IHQTY END) AS &quot;QTY&quot;
  ,      IHUNMS AS &quot;UN&quot;
  ,      HPOCST AS &quot;COST&quot;
  ,      DBCRCY AS &quot;CURRENCY&quot;
  ,      (HPOCST*(CASE WHEN CONCAT(IHTRCD, IHRVCD) IN('D20','D50T','D50Y','E30') THEN IHQTY ELSE -IHQTY END)) AS &quot;TOTAL&quot;
  --,      CASE WHEN VADFCD='D' THEN 1 ELSE DB170P.DBRATE END AS &quot;EXRAT&quot;
  --,      (HPOCST*(CASE WHEN VADFCD='D' THEN 1 ELSE DB170P.DBRATE END)) AS &quot;CLC&quot;
  --,      (HPOCST*(CASE WHEN CONCAT(IHTRCD, IHRVCD) IN('D20','D50T','D50Y','E30') THEN IHQTY ELSE -IHQTY END)*(CASE WHEN VADFCD='D' THEN 1 ELSE DB170P.DBRATE END)) AS &quot;TOTALLC&quot;
  FROM (SELECT * FROM IC090P UNION SELECT * FROM IC090B)AAA 
  LEFT OUTER JOIN (SELECT * FROM PC090P, PC100P WHERE PIBLNO=PHBLNO )X ON TRIM(PIIVNO)=TRIM(IHPLST)  
  ,DB070P , IC010P
  LEFT OUTER JOIN 
                 (SELECT * FROM DB160P)DB160P 
                 ON HCRCD=DB160P.DBCRCD
  LEFT OUTER JOIN
                 (SELECT * FROM DB170P)DB170P
                 on (db160p.DBCRCD=DB170P.DBCRCD
                 AND DATE(CONCAT(CONCAT(CONCAT(CONCAT(DBEFMM,'/'),DBEFDD),'/'),
                 DBEFCC*100+DBEFYY))=DATE((DAYS(DATE(PHCUMM||'/'||PHCUDD||'/'||(PHCUCC*100+PHCUYY)))-2)))
  </code></pre>