我对我继承的一些sql进行了一些更改(下面突出显示),我正在
错误3782 a的搜索条件中的列引用不正确 加入表
我不知道为什么我收到这条消息。任何帮助将不胜感激。
with dqry_cc (mop_cd, mop_desc, group_branch_id, ecr_tmz_name, stn_stn_id , stn_id, grp_brn_id ) as
(select
a.mop_cd ,
a.mop_desc,
so.group_branch_id ,
t.ecr_tmz_name,
so.stn_stn_id,
s.stn_id ,
s.grp_brn_id
from
rfs.stn_ops_hierarchies so,
rfs.mthd_of_pymts a,
rfs.stns s,
rfs.tmzs_map t
where s.stn_id = so.stn_stn_id
and a.mpt_mop_type_code = 'CC'
and s.TMZ = t.TMZS_TMZ
and so.group_id = '01'
and so.region_cd = 'RGN_stl_99'
and so.group_branch_id ='0101')
select *
from
(select
cc.group_branch_id as GpBr,
cc.mop_desc as Descr,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) AS timestamp(6)) as LocalPaydate,
cast(SYSLIB.ERAC_GMT_TO_LCL(ph.pymt_dt, cc.ecr_tmz_name) as date) as ph_pymt_dt,
dr.dvr_srnm as DriverFName,
dr.dvr_frst_name as DriverLName,
ph.name as HolderName,
pd.ticket_no as ECARS2,
cast( case when rb.ecr_lgcy_resv_nbr is null then
case when substr(pd.ticket_no,1,1) = 'D' then
'D'||substr(pd.ticket_no, 2,6)
else
null
end
else 'D'||rb.ecr_lgcy_resv_nbr
end as CHAR(7)) as ECARS1,
rb.rnt_agr_nbr as RntAgrNo,
case when ph.cr_card_trans_typ_cde='R' then
-1*pd.pymt_amt
else
pd.pymt_amt
end as AMOUNT,
pd.cur_curr_cd as Curr,
ph.CR_CARD_NBR as CardNo,
cast(ph.exp_dt as date format 'mm/yy') as ExpireDate,
cast(0 as decimal(15,3)) as AUTH_AMT,
cast(null as date format 'mm/dd/yyyy') as AuthDate,
ph.auth_nbr as AuthNo,
cast(null as char(2)) as Swipe,
cast(null as varchar(60)) as PType,
**pft.Settlement,
pft.First_Six**
from
dqry_cc cc,
rfs_rv.pre_applied_pymts_hdr ph,
rfs_rv.pre_applied_pymts_det pd
left outer join
(select
ra.rnt_agr_nbr,
ra.ecr_ticket_no,
ra.ecre_rent_cntrct_nbr,
ra.ecr_lgcy_resv_nbr,
cc.grp_brn_id --
from
rfs_rv.rnt_agrs ra,
dqry_cc cc
where ra.sta_stn_id_orig_co = cc.stn_id QUALIFY ROW_NUMBER() OVER(PARTITION BY ra.rnt_agr_nbr ORDER BY ra.rnt_agr_nbr) = 1
) rb
on pd.ticket_no = rb.ecr_ticket_no
left outer join
(select
dvr.dvr_srnm,
dvr.dvr_frst_name,
dvr.rdy_rnt_agr_nbr
from rfs_rv.dvr_rras dvr
where dvr.main_dvr_flg = 'MR'
) dr
on rb.rnt_agr_nbr = dr.rdy_rnt_agr_nbr
**left outer join
(select
ft.paymt_mdia_proc_sys_cde as Settlement,
ft.prim_acct_frst_six_dgt_nbr as First_Six,
ft.fin_tran_ref_id
from paymt.fin_tran ft) pft
on pft.fin_tran_ref_id = cast(ph.paph_fin_trans_ref_id as decimal(19,0))**
where ph.pymt_stn_id = cc.stn_stn_id
and ph.mop_mop_cd = cc.mop_cd
and ph.pymt_id = pd.pap_pymt_id
and ph_pymt_dt = 8/5/2015
) z
答案 0 :(得分:2)
您的混合旧式和新式连接语法。如果你遵循这个简单的规则,你的问题永远不会存在:从不使用逗号FROM
子句。 始终使用明确的JOIN
语法。
问题是逗号运算符周围的范围。虽然它在功能上等同于CROSS JOIN
,但第一部分不是第二部分的已知别名。
如果您修复FROM
删除所有逗号,即使您只将逗号更改为CROSS JOIN
,您的问题也会得到解决。但是,我建议使用正确的JOIN
。