Folks:
I'm flummoxed. Why am I getting this error? Apologies for the length
of the log below, but I believe the entire content may be helpful.
ERROR: CLI execute error: [IBM][CLI Driver][DB2/AIX64] SQL0104N An
unexpected token "k2.* ,
value(at.odp_fee_am,0) as odp_f" was found following "), tab3
as ( select". Expected
tokens may include: "<func_name>". SQLSTATE=42601
I'm using multiple intermediate tables ( or whatever you call the
entities created via the WITH ) simply because the query runs for days
otherwise. No issue with the first 2, but the 3rd throws an error.
Any help you can provide would be greatly appreciated. Thanks in
advance.
MPRINT(UDBSQL): options mprint;
MPRINT(UDBSQL): proc sql;
MPRINT(UDBSQL): connect to db2 (database=PRD1 autocommit=no);
MPRINT(UDBSQL): execute (create table droogh2.cap_customer_current
as
MPRINT(UDBSQL): ( with tab1 as ( select k.cust_id, k.efectv_dt ,
value(abm.abm_usage_in,'N') as
abm_usage_in from droogh2.cap_key_file k left join cap_abm_usage_stage
abm on k.cust_id =
abm.cust_id and k.efectv_dt = abm.efectv_dt ), tab2 as ( select k1.*,
value(ap.cust_lon_profit,0)
as cust_lon_profit, value(ap.cust_resl_profit,0) as cust_resl_profit,
value(ap.cust_uloc_profit,0) as cust_uloc_profit,
value(ap.cust_vsa_profit,0) as cust_vsa_profit
,value(ap.customer_profit,0) as
customer_profit ,value(ap.sbb_bloc_limit_am,0) as
sbb_bloc_limit_am, value(ap.sbb_bloc_bal_am,0) as sbb_bloc_bal_am,
value(ap.sbb_loan_limit_am,0)
as sbb_loan_limit_am, value(ap.sbb_loan_bal_am,0) as
sbb_loan_bal_am ,value(ap.lon_me_cl_am,0) as
lon_me_cl_am, value(ap.lon_me_bal_am,0) as lon_me_bal_am,
value(ap.resl_me_cl_am,0) as
resl_me_cl_am, value(ap.resl_me_bal_am,0) as resl_me_bal_am,
value(ap.uloc_me_cl_am,0) as
uloc_me_cl_am ,value(ap.uloc_me_bal_am,0) as uloc_me_bal_am,
value(ap.vsa_me_cl_am,0) as
vsa_me_cl_am, value(ap.vsa_me_bal_am,0) as vsa_me_bal_am,
value(ap.inv_total_prtbal_am,0) as
inv_total_prtbal_am ,case when ap.odp_limit_ct > 0 then
round(ap.odp_limit_am / ap.odp_limit_ct,
1) else 0 end as odp_limit_am , case when primary_chq = 50 then
'Select Service' when primary_chq
= 40 then 'Infinity' when primary_chq = 30 then 'Value Plus' when
primary_chq = 20 then 'Value'
when primary_chq = 10 then 'Plan 60' when primary_chq = 0 then 'Other'
else 'N/A' end as
primary_chq , case when primary_sav = 50 then 'GIA' when primary_sav =
40 then 'Tiered Savings'
when primary_sav = 30 then 'Companion' when primary_sav = 20 then
'Youth' when primary_sav = 0
then 'Other' else 'N/A' end as primary_sav ,case when ap.sbb_bloc_ct >
0 then 'Y' else 'N' end as
sbb_bloc_in ,case when ap.sbb_loan_ct > 0 then 'Y' else 'N' end as
sbb_loan_in from tab1 k1 left
join cap_acct_data_stage ap on k1.cust_id = ap.cust_id and
k1.efectv_dt = ap.efectv_dt ), tab3 as
( select k2.* , value(at.odp_fee_am,0) as odp_fee_am ,
value(at.odp_int_am,0) as odp_int_am ,
value(at.tot_tracked_uloc_bp_trans_ct,0) as
tot_tracked_uloc_bp_trans_ct,
value(at.tot_tracked_uloc_bp_trans_am,0) as
tot_tracked_uloc_bp_trans_am,
value(at.tot_tracked_uloc_rp_trans_ct,0) as
tot_tracked_uloc_rp_trans_ct,
value(at.tot_tracked_uloc_rp_trans_am,0) as
tot_tracked_uloc_rp_trans_am ,
value(at.tot_uloc_trans_am,0) as tot_uloc_trans_am,
value(at.tot_uloc_trans_ct,0) as
tot_uloc_trans_ct, value(at.tot_tracked_uloc_chq_trans_ct,0) as
tot_tracked_uloc_chq_trans_ct,
value(at.tot_tracked_uloc_chq_trans_am,0) as
tot_tracked_uloc_chq_trans_am ,
value(tot_tracked_uloc_bp_trans_ct,0) +
value(tot_tracked_uloc_rp_trans_ct,0) +
value(tot_tracked_uloc_chq_trans_ct,0) as total_tracked_uloc_tran_ct ,
value(tot_tracked_uloc_bp_trans_am,0) as tot_tracked_uloc_bp_trans_am
+
value(tot_tracked_uloc_rp_trans_am,0) +
value(tot_tracked_uloc_chq_trans_am,0) as
total_tracked_uloc_tran_am from tab2 k2 left join cap_acct_trans_stage
at on k2.cust_id =
at.cust_id and k2.efectv_dt = at.efectv_dt ), tab4 as ( select k3.* ,
a.city from tab3 k3 left
join cap_addr_stage a on k3.cust_id = a.cust_id and k3.efectv_dt =
a.efectv_dt ), tab5 as (
select k4.* , value(bu.branch_usage_in,'N') as branch_usage_in from
tab4 k4 left join
cap_branch_usage_stage bu on k4.cust_id = bu.cust_id and k4.efectv_dt
= bu.efectv_dt ), tab7 as (
select k5.* , value(cum.gic_term_in,'N') as gic_term_in ,
value(cum.mut_fund_in,'N') as
mut_fund_in , value(cum.tdct_cust_in,'N') as tdct_cust_in ,
value(cum.tdw_relation,'N') as
tdw_relation from tab5 k5 left join cap_cumoso_stage cum on k5.cust_id
= cum.cust_id and
k5.efectv_dt = cum.efectv_dt ), tab9 as ( select k7.* , cusu.age_yr,
cusu.age_band,
cusu.cust_tenure_mo, cusu.contry_region_mn, cusu.psyte_clustr_mn,
cusu.gender_mn ,
value(cusu.dem_chq_b_am,0) as dem_chq_b_am, value(cusu.dem_sav_b_am,0)
as dem_sav_b_am,
value(cusu.mnyin_total_prtbal_am,0) as mnyin_total_prtbal_am,
value(cusu.mnyout_total_prtbal_am,0) as mnyout_total_prtbal_am,
value(cusu.mny_total_book,0) as
mny_total_book , case when dem_chq_b_ct > 0 then 'Y' else 'N' end as
dem_chq_b_ind , case when
dem_sav_b_ct > 0 then 'Y' else 'N' end as dem_sav_b_ind , case when
dem_chq_p_ct > 0 then 'Y'
else 'N' end as dem_chq_p_ind , case when dem_sav_p_ct > 0 then 'Y'
else 'N' end as dem_sav_p_ind
, case when ( SecLOC_ct > 0 or mtg_ct > 0 ) then 'Y' else 'N' end as
RESL_Relationship , case
when secloc_ct > 0 then 'Y' else 'N' end as loc_in , case when
unsecloc_ct > 0 then 'Y' else 'N'
end as loc_unsec_in , case when mtg_ct > 0 then 'Y' else 'N' end as
mtg_in , case when lon_ct > 0
then 'Y' else 'N' end as lon_in , case when vsa_ct > 0 then 'Y' else
'N' end as vsa_in , ( case
when secloc_ct > 0 then 1 else 0 end + case when unsecloc_ct > 0 then
1 else 0 end + case when
lon_ct > 0 then 1 else 0 end + case when mtg_ct > 0 then 1 else 0 end
+ case when vsa_ct > 0 then
1 else 0 end + case when dem_ct > 0 then 1 else 0 end + case when
fixunreg_ct > 0 or varunreg_ct
> 0 then 1 else 0 end + case when fixreg_ct > 0 or varreg_ct > 0 then 1 else 0 end ) as
tot_prod_ct from tab7 k7 left join cap_cusu_stage cusu on k7.cust_id =
cusu.cust_id and
k7.efectv_dt = cusu.efectv_dt ), tab10 as ( select k9.* ,
value(ci.db_am,0) as db_am,
value(ci.fp_am,0) as fp_am, value(ci.ia_am,0) as ia_am,
value(ci.pcg_am,0) as pcg_am,
value(ci.pic_am,0) as pic_am, value(ci.pt_am,0) as pt_am , case when
pt_ct > 0 then 'Y' else 'N'
end as pt_ind , case when pcg_ct > 0 then 'Y' else 'N' end as
pcg_ind , case when pic_ct > 0 then
'Y' else 'N' end as pic_ind , case when ia_ct > 0 then 'Y' else 'N'
end as ia_ind , case when
fp_ct > 0 then 'Y' else 'N' end as fp_ind , case when db_ct > 0 then
'Y' else 'N' end as db_ind ,
case when pt_ct > 0 then 'PT' when pcg_ct > 0 then 'PCG' when pic_ct >
0 then 'PIC' when ia_ct >
0 then 'PIA' when fp_ct > 0 then 'FP' when db_ct > 0 then 'DB' else '
' end as tdw_relationship
from tab9 k9 left join cap_investment_stage ci on k9.cust_id =
ci.cust_id and k9.efectv_dt =
ci.efectv_dt ), tab13 as ( select k10.* , sr.sic_id,
value(sr.total_retail_sr_am,0) as
total_retail_sr_am, value(sr.total_wealth_sr_am,0) as
total_wealth_sr_am,
value(sr.total_sbb_sr_am,0) as total_sbb_sr_am from tab10 k10 left
join cap_salesrevenue_stage sr
on k10.cust_id = sr.cust_id and k10.efectv_dt = sr.efectv_dt ), tab15
as ( select k13.* ,
value(we.web_usage_in,'N') as web_usage_in ,
value(we.web_broker_usage_in,'N') as
web_broker_usage_in from tab13 k13 left join cap_web_usage_stage we on
k13.cust_id = we.cust_id
and k13.efectv_dt = we.efectv_dt ) select k15.* ,
value(sp.sbb_personal_relationship,'N') as
sbb_personal_relationship from tab15 k15 left join cap_sbb_personal sp
on k15.cust_id =
sp.cust_id and k15.efectv_dt = sp.efectv_dt order by k15.cust_id,
k15.efectv_dt) definition only
MPRINT(UDBSQL): not logged initially
MPRINT(UDBSQL): ) by db2;
ERROR: CLI execute error: [IBM][CLI Driver][DB2/AIX64] SQL0104N An
unexpected token "k2.* ,
value(at.odp_fee_am,0) as odp_f" was found following "), tab3
as ( select". Expected
tokens may include: "<func_name>". SQLSTATE=42601
Serge Rielau - 25 Oct 2008 19:55 GMT
> Folks:
>
[quoted text clipped - 174 lines]
> as ( select". Expected
> tokens may include: "<func_name>". SQLSTATE=42601
Not knowing the rest of the statement I'm taking a guess: It may be you
are missing a closing bracket to finish the previous view.
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Tonkuma - 28 Oct 2008 14:41 GMT
You should format your code to understand what you wrote as your code.
Following is my favolit way of formatting.
I found a syntax error in the SELECT list by looking into this
formatted code.
,tab3 as (
select k2.*
, value(at.odp_fee_am,0) as odp_fee_am
, value(at.odp_int_am,0) as odp_int_am
, value(at.tot_tracked_uloc_bp_trans_ct,0) as
tot_tracked_uloc_bp_trans_ct
, value(at.tot_tracked_uloc_bp_trans_am,0) as
tot_tracked_uloc_bp_trans_am
, value(at.tot_tracked_uloc_rp_trans_ct,0) as
tot_tracked_uloc_rp_trans_ct
, value(at.tot_tracked_uloc_rp_trans_am,0) as
tot_tracked_uloc_rp_trans_am
, value(at.tot_uloc_trans_am,0) as tot_uloc_trans_am
, value(at.tot_uloc_trans_ct,0) as tot_uloc_trans_ct
, value(at.tot_tracked_uloc_chq_trans_ct,0) as
tot_tracked_uloc_chq_trans_ct
, value(at.tot_tracked_uloc_chq_trans_am,0) as
tot_tracked_uloc_chq_trans_am
, value(tot_tracked_uloc_bp_trans_ct,0)
+ value(tot_tracked_uloc_rp_trans_ct,0)
+ value(tot_tracked_uloc_chq_trans_ct,0) as
total_tracked_uloc_tran_ct
, value(tot_tracked_uloc_bp_trans_am,0) as
tot_tracked_uloc_bp_trans_am
+ value(tot_tracked_uloc_rp_trans_am,0)
+ value(tot_tracked_uloc_chq_trans_am,0) as
total_tracked_uloc_tran_am
from tab2 k2
left join
cap_acct_trans_stage at
on k2.cust_id = at.cust_id
and k2.efectv_dt = at.efectv_dt
)