Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Propagate row data until next date is encountered - response (10) by Harry Droogendyk

$
0
0

Found it.  Table travel_cum_os_reserves had some duplicate event_dt values within clm_bnft_cse_id due to the way the incoming detail data was ordered. Gave up on figuring out the order and added a sub-query to summarize by clm_bnft_cse_id & event_dt before doing the cumulative sum / expand.
Added the FOR clause to the EXPAND ON to limit the data expanded.  Very cool functionality, thanks Dieter.


create table dl_trav_data.hd_travel_cum_os_reserves as (

			/*  rows unbounded preceding creates cumulative sum by Case and date  */
			 select	clm_bnft_cse_id
						,	event_dt
						,	sum(evnt_amt)
								over ( partition by clm_bnft_cse_id order by event_dt
											rows unbounded preceding )				as os_reserve_amt
				from ( 
			 
			 				/*  Reserves are set at product / risk level, must first summarize by date for Case level outstanding reserves  */
			 				
							 select r.clm_bnft_cse_id
							 	,		e.fncl_evnt_perd_strt_dt		as event_dt
							 	,		sum(case when txn_typ_cd = 'PMNT' then evnt_amt * -1 else evnt_amt end) as evnt_amt
							 	
						     from dl_trav_data.hd_travel_case_active 						a,
								  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		<= '2013-08-27' 
				
							   and a.clm_bnft_cse_id			= r.clm_bnft_cse_id
							   and a.clm_bnft_cse_id			= c.clm_bnft_cse_id
				
							   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-27'
							   and c.clm_cse_ctr_cd				= e.clm_cse_ctr_cd
							   
							   group by 1,2
			   	) as a
						)
			with data primary index ( clm_bnft_cse_id );

drop table dl_trav_data.hd_travel_daily_os_reserves ;
			
create table dl_trav_data.hd_travel_daily_os_reserves as (

			 select	clm_bnft_cse_id
				,	os_reserve_amt
				, 	begin(event_dt2)		as event_dt
			   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 dl_trav_data.hd_travel_cum_os_reserves
				 	) as dt
			   expand on period_dt as event_dt2 by interval '1' day for period(cast ('2011-10-30' as date),cast('2013-08-27' as date))
		
                )
                with data primary index ( clm_bnft_cse_id )
                

 
 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>