SQL for DB2无法在Crystal Reports中使用

时间:2013-08-06 15:02:38

标签: sql db2 ibm-midrange

我正在尝试在水晶报表中针对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) )

1 个答案:

答案 0 :(得分: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