我们有这个 SQL,它通过了 Crystal Reports,但它没有返回任何“PAL”行。orig Query/400 非常简单:
它是 ICLOCMLM 和 ICBLDTIR 之间的匹配连接;加入这些:(加入 1 或加入 2 相同的问题)
T01.LMLOC1 EQ T02.IRLOC1
T01.LMLOC2 EQ T02.IRLOC2
T01.LMLOC3 EQ T02.IRLOC3
选择记录: T01.LMLTPC LIST 'PAL' 'RAK'
排序:
rty A/D Field
10 A T01.LMLOC1
20 A T01.LMLOC2
30 A T01.LMLOC3
并创建一个输出文件:替换 BLDPALQ 选项 1。
然后在添加 BAL 文件后添加此文件,为我们提供所需的记录,但由于某种原因,在此 SQL 中未添加 PAL 记录。只有 RAK。IOW、Query/400 和 CPYF 正在做我们需要的事情,但不是这个 SQL。
CPYF FROMFILE(ASTDTA/ICBALMIE) +
TOFILE(ASTCCDTA/ACBALMPK) +
MBROPT(*REPLACE) FMTOPT(*MAP *DROP)
MONMSG CPF0000
*/
CPYF FROMFILE(TEMPLIB/BLDPALQ) +
TOFILE(ASTCCDTA/ACBALMPK) +
MBROPT(*ADD) FMTOPT(*MAP *DROP)
MONMSG CPF0000
SELECT
LMLTPC,
COALESCE(IRLOC1,'') as IRLOC1,
COALESCE(IRLOC2,'') as IRLOC2,
COALESCE(IRLOC3,'') as IRLOC3,
IRPRT#,
IRQOH#,
IRWHS#,
'' as IEPRT#,
'.00' as IEQOH#,
'' as IELOC1,
'' as IELOC2,
'' as IELOC3,
'' as IEWHS#
FROM ASTDTA.ICLOCMLM mlm
left join ASTDTA.ICBLDTIR tir
on mlm.LMLOC1 = tir.IRLOC1
and mlm.LMLOC2 = tir.IRLOC2
and mlm.LMLOC3 = tir.IRLOC3
where LMLTPC in ('PAL', 'RAK')
UNION ALL
SELECT
' ' as LMLTPC,
' ' as IRLOC1,
' ' as IRLOC2,
' ' as IRLOC3,
'' as IRPRT#,
'.00' as IRQOH#,
'' as IRWHS#,
IEPRT#,
IEQOH#,
IELOC1,
IELOC2,
IELOC3,
IEWHS#
FROM ASTDTA.ICBALMIE
奇怪的是,当我在 400 上运行此查询时,我确实得到了 PAL 记录,所以它一定是加入中的东西。
SELECT ALL
T01.LMCOM#,
T01.LMWHS#,
T01.LMLOC1,
T01.LMLOC2,
T01.LMLOC3,
T01.LMLTPC,
T01.LMLCT1,
T01.LMLCT2,
T01.LMRIDC,
T01.LMQTM#,
T01.LMQMX#,
T01.LMWGHT,
T01.LMACTF
FROM ASTDTA/ICLOC1 T01
WHERE t01.LMLTPC = 'PAL'
我已完全加入,但仍然无法正常工作:
SELECT
T01.LMLTPC,
T02.IRCOM#,
T02.IRWHS#,
T02.IRPRT#,
T02.IRUM,
T02.IRLOC1,
T02.IRLOC2,
T02.IRLOC3,
T02.IRLOT#,
T02.IRFL50,
T02.IREXPD,
T02.IRQOH#,
T02.IRQTM#,
T02.IRQMX#,
T02.IRLTPC,
T02.IRQCM#
FROM ASTDTA.ICLOC1 T01,
ASTDTA.ICBLD1 T02
WHERE T01.LMLOC1 = T02.IRLOC1
AND T01.LMLOC2 = T02.IRLOC2
AND T01.LMLOC3 = T02.IRLOC3
ORDER BY T01.LMLOC1 ASC, T01.LMLOC2 ASC, T01.LMLOC3 ASC