This was working, but I've managed to break it. Now generating the following error when creating the last table, TRAVEL_DAILY_OS_RESERVES.
Invalid Period value constructor. The beginning bound must be less than the ending bound.
I've dumped the TRAVEL_CUM_OS_RESERVES and no event_dt value > current_date. Any ideas how to further debug this to determine why the PERIOD function is throwing this error?
The Teradata syntax is wrapped in SAS code since we access the DB through our SAS server. The stuff in the execute() clause is native Teradata syntax.
Thanks
proc sql;
connect to teradata ( &password database = ddwv04i connection=global);
/* Create a temp table to house cumulative reserves by date */
execute(
create volatile table travel_cum_os_reserves as (
select r.clm_bnft_cse_id
, e.fncl_evnt_perd_strt_dt as event_dt
/* 2nd and subsequent parms order the detail data as it comes into the CSUM function */
, csum(case when txn_typ_cd = 'PMNT' then evnt_amt * -1 else evnt_amt end
, r.clm_bnft_cse_id
, e.fncl_evnt_perd_strt_dt
, e.travel_cse_prod_txt
, e.rsk_cd
, e.seq_no
) as os_reserve_amt
from ddwv04i.ins_clm_fncl_evnt e,
ddwv04i.ins_clm_bnft_cse_evnt_reltn r,
ddwv04i.ins_clm_bnft_cse c
where e.evnt_sys_src_id = 75
and e.evnt_sys_src_id = r.evnt_sys_src_id
and e.evnt_key_id = r.evnt_key_id
and e.txn_typ_cd in ( 'PMNT', 'ADJ' )
and e.txn_sub_typ_cd not in ( 'SUB' )
and e.fncl_evnt_perd_strt_dt <= cast ('2013-08-26' as date)
and c.clm_bnft_cse_id = r.clm_bnft_cse_id
and c.clm_bnft_cse_sys_src_id = r.evnt_sys_src_id
and c.snap_dt = '2013-08-26'
and c.clm_cse_ctr_cd = e.clm_cse_ctr_cd
group by r.clm_bnft_cse_id
/* We only want to keep the last row we've accumulated for this date */
qualify row_number() over
( partition by r.clm_bnft_cse_id
, e.fncl_evnt_perd_strt_dt
, e.travel_cse_prod_txt
, e.rsk_cd
order by e.seq_no desc
) = 1
)
with data primary index ( clm_bnft_cse_id )
on commit preserve rows
) by teradata;
execute ( commit work ) by teradata;
/* Expand the cumulative reserves table to include all dates */
execute(
create volatile table travel_daily_os_reserves as (
select clm_bnft_cse_id
, begin(event_dt2) as event_dt
, os_reserve_amt
from (
select clm_bnft_cse_id
, os_reserve_amt
, period(event_dt,
coalesce( min(event_dt)
over ( partition by clm_bnft_cse_id
order by event_dt
rows between 1 following and 1 following), current_date )) as period_dt
from travel_cum_os_reserves
) as dt
expand on period_dt as event_dt2 by interval '1' day
)
with data primary index ( clm_bnft_cse_id )
on commit preserve rows
) by teradata;
execute ( commit work ) by teradata;
quit;
This was working, but I've managed to break it. Now generating the following error when creating the last table, TRAVEL_DAILY_OS_RESERVES.
Invalid Period value constructor. The beginning bound must be less than the ending bound.
I've dumped the TRAVEL_CUM_OS_RESERVES and no event_dt value > current_date. Any ideas how to further debug this to determine why the PERIOD function is throwing this error?
The Teradata syntax is wrapped in SAS code since we access the DB through our SAS server. The stuff in the execute() clause is native Teradata syntax.
Thanks