0

我正在尝试在水晶报告中针对 AS/400 db2 数据库运行此 SQL,但出现错误

无法从数据库中检索数据”详细信息 42000 IBM ISeries ACCESS ODBC 驱动程序 DB2 UDB SQL0104 令牌无效。有效令牌 <语句结束> 数据库供应商代码 104

(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
 (SELECT LMLTPC, LMLOC1, LMLOC2, LMLOC3 FROM ASTDTA.ICLOCMLM WHERE
 LMLTPC='PAL') t1
 left outer join
 (SELECT IRLOC1, IRLOC2, IRLOC3, IRPRT#, IRQOH#, IRWHS# FROM
 ASTDTA.ICBLDTIR  ) t2
 On LMLOC1=IRLOC1 AND LMLOC2=IRLOC2 AND LMLOC3=IRLOC3 )
 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) )
4

1 回答 1

3

最后一个括号应该是有问题的。删除它,以便您的代码如下所示:

...
...
IEWHS# FROM ASTDTA.ICBALMIE)

我在 AS/400 v6r1 系统上使用虚拟数据进行了测试。SQL 将毫无问题地编译并生成数据。希望 Crystal Reports 在使用结果数据时不会有太大问题。我无权访问 Crystal Reports 来测试结果。

仅当您对主动提供的建议感兴趣时,我才会提出一种稍微不同的 SQL 编写方式:

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 = 'PAL'

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
于 2013-08-06T15:39:55.927 回答