我们有这个SQL,它传递了Crystal Reports,但没有返回任何"PAL"行。原始查询/400非常简单:
它是ICLOCMLM和ICBLDTIR之间的匹配Join;加入这些:(加入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
您可能会得到所需的行,但会使用COALESCE来屏蔽它们。试着从左侧选择列,看看这些行是否是您期望的行:
SELECT
LMLTPC,
LMLOC1,
LMLOC2,
LMLOC3,
IRPRT#...
提示:
您可以使用RTVQMQRY命令从Query/400查询生成SQL
RTVQMQRY QMQRY(someqry) +
SRCFILE(mylib/qsqlsrc) +
ALWQRYDFN(*YES)