SELECT evt_object,evt_rstatus,evt_object_org,evt_object_desc,ksf_pk  ksf_pk,ksf_code ksf_code,ksf_hazard_desc ksf_hazard_desc,
(SELECT uco_desc FROM r5ucodes WHERE uco_code = ksf_hazard_type AND uco_rentity = 'HZTP') ksf_hazard_typedesc,
ksf_precaution_desc ksf_precaution_desc,
(SELECT uco_desc FROM r5ucodes WHERE uco_code =  ksf_timing AND uco_rentity = 'PCTI') ksf_timing_desc,
KSF_PRECAUTIONAPPLIED KSF_PRECAUTIONAPPLIED, (SELECT uco_desc FROM r5ucodes where uco_code = KSF_RESPONSIBILITY and uco_rentity = 'RESP') KSF_RESPONSIBILITY
FROM R5WORKSAFETY,R5EVENTS
WHERE   ksf_code = evt_code AND ksf_pk IN ( select ksf_pk FROM r5worksafety WHERE ksf_code = <param.workordernum> AND ksf_rentity = 'EVNT'
UNION
SELECT ksf_pk FROM r5worksafety, r5events WHERE evt_routeparent = <param.workordernum> AND ksf_rentity = 'EVNT' AND ksf_code = evt_code)
ORDER BY KSF_RESPONSIBILITY ASC, ksf_code ASC,ksf_timing_desc ASC, ksf_hazard_desc ASC, ksf_precaution_desc ASC

