New section hours :

SELECT * FROM aerion.vw_hours where emp_id = '807';
#idemp_org_hrs_days_cy, idemp_org_hrs, emp_org_hrs_comp_id, comp_nm, idhours_cy_bc_nm, idinv_nm, hoursdate_fmt, starttime, endtime, off_time, totaltime
SELECT * FROM aerion.vw_engage_entity;
#SELECT * FROM aerion.vw_engage_entity where engage_ref_tab = 'Employee' and engage_ref_id = '807';
#srv_client_nm, srv_vendor_nm, bill_start_dt_fmt, bill_end_dt_fmt, bill_cycle, bill_pay_rate, bill_pay_rate_xtra, tentative_e_dt_fmt, cloud_drive

SELECT * FROM aerion.emp where emp_id in  ('2859', '2860', '2912');
SELECT * FROM aerion.emp_org where emp_id in  ('2859', '2860', '2912');
SELECT * FROM aerion.emp_org_hrs;
SELECT * FROM aerion.vw_emp_org_hrs;

#SELECT * FROM aerion.emp_org_hrs_days;
SELECT * FROM aerion.vw_emp_org_hrs_days;
SELECT * FROM aerion.emp_org_hrs_days_cy;

Before making emp_org_hrs_days_cy null i.e before loop,

Update hours set idemp_org_hrs_days_cy = NULL where idemp_org_hrs = ’57’

After loop 

Update emp_org_hrs_days_cy as a a.day_hrs_actual_tm = b.totaltime , a.day_off_actual = b.off_time , day_pay_actual_amt = (b.totaltime * a.pay_amt(view) where a.hoursdate = b.(trim_to_day(day_start_tm);

Update hours as a set a.idemp_org_hrs_days_cy = a.idemp_org_hrs_days_cy where a.idemp_org_hrs = (select b.idemp_org_hrs from  vw_emp_org_hrs_days_cy) 
##and idemp_org_hrs_days_cy is null;

Get hours where not = to ‘Holiday’
Insert Saturday and Sunday hours
Below in separate function : - 

Update emp_org_hrs as a set a.frm_to_org_hrs_days = (a.to_dt - a.from_dt), org_hrs_forecast = (select sum(day_hrs_forcast_tm) from vw_emp_org_hrs_days_cy as b where a.idemp_org_hrs = b.idemp_org_hrs), org_hrs_actual = (select sum(day_hrs_actual_tm) from vw_emp_org_hrs_days_cy as b where a.idemp_org_hrs = b.idemp_org_hrs)

Update emp_org 

======== Hours ============

SELECT * FROM aerion.hours where emp_id = '3284' order  by hour_id;
SELECT * FROM aerion.vw_hours where emp_id = '3284' order  by hour_id;

#SELECT * FROM aerion.emp where emp_id in  ('2859', '2860', '2912');
SELECT * FROM aerion.emp_org where emp_id = '3284';
SELECT * FROM aerion.emp_org_hrs where emp_org_id in 
(SELECT emp_org_id  FROM aerion.emp_org where emp_id = '3284');
SELECT * FROM aerion.emp_org_hrs_days where  idemp_org_hrs in 
(SELECT idemp_org_hrs FROM aerion.emp_org_hrs where emp_org_id in 
(SELECT emp_org_id  FROM aerion.emp_org where emp_id = '3284'));
SELECT * FROM aerion.emp_org_hrs_days_cy where idemp_org_hrs_days in 
(SELECT idemp_org_hrs_days FROM aerion.emp_org_hrs_days where  idemp_org_hrs in 
(SELECT idemp_org_hrs FROM aerion.emp_org_hrs where emp_org_id in 
(SELECT emp_org_id  FROM aerion.emp_org where emp_id = '3284')));

Engage Entity

SELECT * FROM aerion.engage_entity where engage_ref_id = '7';
SELECT * FROM aerion.vw_engage_entity where engage_ref_id = '7';
SELECT * FROM aerion.hours_cy_bc where idengage_entity in 
(SELECT idengage_entity FROM aerion.engage_entity where engage_ref_id = '7') order by idengage_entity, bc_st_dt;
SELECT * FROM aerion.hours_cy_tc where idengage_entity in 
(SELECT idengage_entity FROM aerion.engage_entity where engage_ref_id = '7');
SELECT * FROM aerion.hours where emp_id = '7' order  by hr_st_dt desc;
SELECT * FROM aerion.vw_hours where emp_id = '7' order  by hr_st_dt desc;

Emp Vacation

SELECT * FROM aerion.emp_org where emp_org_id = '1440';
SELECT * FROM aerion.emp_org_hrs where emp_org_id = '1440';

SELECT * FROM aerion.emp_org_vac where idemp_org_hrs in 
(SELECT idemp_org_hrs FROM aerion.emp_org_hrs where emp_org_id = '1440');