
select 
e.epo_aspect as aspect,
e.epo_object as equipmentcode,
o.obj_desc as equipmentdescription,
e.epo_object_org as equipmentorganization,
o.obj_obtype as equipmenttype,
e.epo_code as inspectioncode,
e.epo_date as inspectiondate,
e.epo_finding as inspectionfinding,
e.epo_location as inspectionlocation,
e.epo_method as inspectionmethod,
e.epo_comment as inspectionnote,
e.epo_result as inspectionresult,
e.epo_value as inspectionvalue,
e.epo_inspector as inspector,
e.epo_create as newworequired,
e.epo_point as pointcode,
p.POI_DESC as pointdesc,
e.epo_pointtype as pointtypecode,
e.epo_line as sequencenumber,
e.epo_stwo as standardwo,
e.epo_uom as uom
FROM   r5points p, r5eventpoints e  left outer join r5objects o ON e.epo_object = o.obj_code and e.EPO_OBJECT_ORG = o.OBJ_ORG
WHERE  e.epo_event  = <param.workordernum>
AND   (( e.epo_object     = p.poi_object
AND e.epo_object_org = p.poi_object_org )
OR  ( p.poi_object     = (SELECT obj_category
FROM   r5objects 
WHERE  obj_code    = e.epo_object
AND    obj_org     = e.epo_object_org 
AND    obj_obrtype IN ('A','P','S'))
AND poi_object_org = '*' ) 
 AND NOT EXISTS( SELECT 'x'  
 FROM  r5points p1 
 WHERE e.epo_object = p1.poi_object
AND   e.epo_object_org = p1.poi_object_org
AND   e.epo_point      = p1.poi_point
AND   e.epo_pointtype  = p1.poi_pointtype ) )
AND    e.epo_point      = poi_point
AND    e.epo_pointtype  = poi_pointtype
ORDER BY sequencenumber