派生表错误/对象包含受限制的字符

时间:2015-05-13 20:30:53

标签: sql teradata

我第一次尝试使用派生表,并收到一条错误消息“SELECT failed 6725对象名称包含受限制的字符。我不确定有什么问题。我已经在下面包含了SQL 。 任何帮助将不胜感激。谢谢。

WITH drvd_amts (acct_nbr, grp_br_ps_org_id, PSAmt)
AS
(SELECT 
d.acct_nbr,
d.grp_br_ps_org_id,
sum(d.pstd_ttl_amt) as PSAmt

FROM psfs.ps_gl_acct_ldgr d
WHERE d.fiscal_yr_mth_nbr BETWEEN 201500 AND 201508
AND d.acct_nbr BETWEEN 150000 AND 160500

GROUP BY d.grp_br_ps_org_id, d.acct_nbr)

SELECT
a.FA_ACCT,
a.ERACBR,
a.deptid,
a.FA_AMT,
da.PSAmt,

CASE WHEN da.PSAmt IS NULL THEN a.FA_AMT
ELSE a.FA_AMT - da.PSAmt END AS DIFF

FROM 

(SELECT 
    pdr.account_fa AS FA_ACCT,
    ir.erac_branch_lgcy_cd AS ERACBR,
    pdr.deptid,
    SUM(pdr.COST) AS FA_Amt

FROM PSFS.PS_DEPR_RPT pdr 

LEFT JOIN INTGRT_RPT.DIM_LOCATION ir ON pdr.deptid = ir.erac_branch_ps_org_cd AND ir.curr_lrd_row_flg = 1

INNER JOIN RFS.STN_OPS_HIERARCHIES soh ON pdr.deptid = soh.department

WHERE pdr.BUSINESS_UNIT = 'A0465'
AND pdr.BOOK = 'PERFORM'
AND pdr.FISCAL_YEAR = 2015
AND pdr.ACCOUNTING_PERIOD = 8
AND pdr.GROUP_ASSET_FLAG <> 'M'

GROUP BY FA_ACCT, ERACBR, deptid

UNION All

SELECT
pdr.account_ad AS FA_ACCT,
ir.erac_branch_lgcy_cd AS ERACBR,
pdr.deptid,
SUM(pdr.depr_ltd) AS FA_Amt

FROM PSFS.PS_DEPR_RPT pdr 

LEFT JOIN INTGRT_RPT.DIM_LOCATION ir ON pdr.deptid = ir.erac_branch_ps_org_cd AND ir.curr_lrd_row_flg = 1

INNER JOIN RFS.STN_OPS_HIERARCHIES soh ON pdr.deptid = soh.department

WHERE pdr.BUSINESS_UNIT = 'A0465'
AND pdr.BOOK = 'PERFORM'
AND pdr.FISCAL_YEAR = 2015
AND pdr.ACCOUNTING_PERIOD =8
AND pdr.GROUP_ASSET_FLAG <> 'M'

GROUP BY FA_ACCT, ERACBR, deptid ) a

LEFT JOIN drvd_amts da ON a.deptid = da.grp_br_ps_org_id
 AND a.fa_acct = da.acct_nbr

GROUP BY 1,2,3,4,5,6

HAVING DIFF <> 0

UNION

SELECT 
daq.acct_nbr AS FA_ACCT,
ir.erac_branch_lgcy_cd AS ERACBR,
daq.grp_br_ps_org_id,
b.FA_AMT,
daq.PSAmt,

CASE WHEN b.fa_amt IS NULL THEN daq.psamt
    ELSE b.FA_AMT – daq.psamt END AS DIFF

FROM drvd_amts daq

LEFT JOIN INTGRT_RPT.DIM_LOCATION ir ON daq.grp_br_ps_org_id = ir.erac_branch_ps_org_cd AND ir.curr_lrd_row_flg = 1 

LEFT  JOIN 

    (SELECT 
        pdr.account_fa AS FA_ACCT,
        pdr.deptid,
        SUM(pdr.COST) AS FA_Amt

    FROM PSFS.PS_DEPR_RPT pdr 

    INNER JOIN RFS.STN_OPS_HIERARCHIES soh ON pdr.deptid = soh.department

    WHERE pdr.BUSINESS_UNIT = 'A0465'
    AND pdr.BOOK = 'PERFORM'
    AND pdr.FISCAL_YEAR = 2015
    AND pdr.ACCOUNTING_PERIOD = 8
    AND pdr.GROUP_ASSET_FLAG <> 'M'

    GROUP BY FA_ACCT, deptid

UNION All

    SELECT
    pdr.account_ad AS FA_ACCT,
    pdr.deptid,
    SUM(pdr.depr_ltd) AS FA_Amt

    FROM PSFS.PS_DEPR_RPT pdr 

    INNER JOIN RFS.STN_OPS_HIERARCHIES soh ON pdr.deptid =  soh.department

    WHERE pdr.BUSINESS_UNIT = 'A0465'
    AND pdr.BOOK = 'PERFORM'
    AND pdr.FISCAL_YEAR = 2015
    AND pdr.ACCOUNTING_PERIOD = 8
    AND pdr.GROUP_ASSET_FLAG <> 'M'

    GROUP BY FA_ACCT, deptid) b

ON daq.grp_br_ps_org_id = b.deptid
AND daq.acct_nbr = b.fa_acct

Where ir.ody_group_cd = 'A0465'

GROUP BY 1,2,3,4,5,6

HAVING DIFF <> 0

ORDER BY 1, 3

1 个答案:

答案 0 :(得分:2)

不知道你是怎么输入它的(你是用MS Word编写代码吗?),但在第85行中有一个非法字符:

ELSE b.FA_AMT – daq.psamt END AS DIFF

&#39; - &#39;不是U+002D HYPHEN-MINUS而是U+2013 EN DASH,只需替换它。