SQL 错误 [42972]:[SQL0338] JOIN 谓词或 MERGE ON 子句无效

SQL Error [42972]: [SQL0338] JOIN predicate or MERGE ON clause not valid

SQL Error [42972]: [SQL0338] JOIN predicate or MERGE ON clause not valid.

我正在尝试 运行 下面的查询,但是 table DB170P 中的 JOIN 发生错误。你能帮帮我吗?

SELECT ACBAC AS "CBUYER"
,      HBAC AS "BORDER"
,      IHTRCD AS "TRANS"
,      IHRVCD AS "REV"
,      DATE(CONCAT(CONCAT(CONCAT(CONCAT(IHTRMM,'/'),IHTRDD),'/'),IHTRCC*100+IHTRYY)) AS "RECD"
,      VADFCD AS "DF"
,      HVEND  AS "VENC"
,      VSNAME AS "VNAME"
,      IHSRNO AS "SER"
,      DATE(PHCUMM||'/'||PHCUDD||'/'||(PHCUCC*100+PHCUYY)) "CUST_DATE"
,      PHBLNO AS "B/L"
,      IHPLST AS "NF"
,      IHORNO AS "PO"
,      IHPNO  AS "PN"
,      MODEL
,      (CASE WHEN CONCAT(IHTRCD, IHRVCD) IN('D20','D50T','D50Y','E30') THEN IHQTY ELSE -IHQTY END) AS "QTY"
,      IHUNMS AS "UN"
,      HPOCST AS "COST"
,      DBCRCY AS "CURRENCY"
,      (HPOCST*(CASE WHEN CONCAT(IHTRCD, IHRVCD) IN('D20','D50T','D50Y','E30') THEN IHQTY ELSE -IHQTY END)) AS "TOTAL"
--,      CASE WHEN VADFCD='D' THEN 1 ELSE DB170P.DBRATE END AS "EXRAT"
--,      (HPOCST*(CASE WHEN VADFCD='D' THEN 1 ELSE DB170P.DBRATE END)) AS "CLC"
--,      (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 "TOTALLC"
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)))

这个LEFT OUTER JOIN (SELECT * FROM DB170P)DB170P语法很奇怪...
LEFT OUTER JOIN DP170P 是您真正需要的。

在与 DB170P 的联接中尝试将数据类型转换为日期数据类型时可能会出错。

您是否在作业日志中查看过其他错误信息?

我建议

  • 从嵌套 Table 表达式 (NTE) 移动到通用 Table 表达式 (CTE)
  • 构建一个用户定义函数 (UDF) 来处理日期转换(或下载开源 iDate
  • 在 CTE 中通过 UDF 进行日期转换
  • 使用显式 join
  • 通常不使用 SELECT * 是个好主意,即使您确实需要所有列

CTE 版本的开头可能是这样的...

with AAAA as (SELECT trim(IHPLST) as lastInvNbr
             FROM IC090P 
             UNION 
             SELECT trim(IHPLST) 
             FROM IC090B)
 , X as (SELECT trim(PIIVNO) as InvNbr 
         FROM PC090P 
         join PC100P 
           on PIBLNO=PHBLNO
         )
select * 
from aaaa join X on aaaa.lastInvNbr = x.InvNo

除了可重用之外,CTE 还可以轻松地打一个 SELECT * FROM mycte 以便您可以在构建语句时查看中间结果。