select 
cast(ACT_ACT as varchar(30)) as booactivity,
boo_hours as hours,
boo_date as boodate,
boo_person as employee,
boo_octype as octype,
boo_mrc as department,
boo_acd as booid,
boo_event as booevent,
boo_trade as bootrade,
boo_code as boocode,
r5bookedhours.dmltype as boodmltype,
boo_correction_ref as boocorrectionref,
boo_correctiondate as boocorrectiondate,
(SELECT date(CLP_CLOSED) FROM R5CLOSEDPERIODS order by CLP_CLOSED desc) as boomaxclosingdate,
case e.evt_object when (select e1.evt_object from r5events e1 where e1.evt_code= <param.jobnum> and e1.evt_multiequip = '+'and e1.evt_code=e.evt_code) then <param.woheaderequipment> else e.evt_object end as equipmentcode
from r5bookedhours, r5activities, r5events e 
where  (case when e.EVT_JOBTYPE='MEC'  then e.EVT_ROUTEPARENT else e.evt_code end) = <param.jobnum> and e.evt_rstatus IN ( 'C', 'R' )     
and act_event =  <param.jobnum>  and boo_event = e.evt_code        
and boo_act = act_act    
