Derived table error / object contains restricted characters

Database
N/A

Derived table error / object contains restricted characters

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 130500 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'
--AND ( ? is null or soh.REGION_CD = ?)

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'
--AND ( ? is null or soh.REGION_CD = ?)
 
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'
 --AND ( ? is null or soh.REGION_CD = ?)

 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'
 --AND ( ? is null or soh.REGION_CD = ?)

 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

I'm trying to use a derived table for the first time and am getting an error message that says "SELECT failed 6725 object name contains restricted characters".  I'm not sure what is wrong.  I've included the SQL below.  Any help would be greatly appreciated.  Thank You

1 REPLY
N/A

Re: Derived table error / object contains restricted characters

Don't know how you typed it (did you write the code in MS Word?), but in line 85 there's an illegal character:

ELSE b.FA_AMT – daq.psamt END AS DIFF

The '-' is not U+002D HYPHEN-MINUS but U+2013 EN DASH, simply replace it.