select 
a.apo_aspect as aspect,
a.apo_method as inspectionmethod,
a.apo_point as pointcode,
a.apo_pointtype as pointtypecode,
p.poi_desc as pointtypedesc,
a.apo_uom as uom
from r5aspectpoints a, r5points p       
where a.apo_object = p.poi_object        
and a.apo_object_org = p.poi_object_org        
and p.poi_obtype = a.apo_obtype       
and p.poi_point = a.apo_point       
and p.poi_pointtype = a.apo_pointtype       
and ((a.apo_object = <equipcode> and a.apo_object_org = <equiporg>)              
or (a.apo_object = <equipcategory>                  
and not exists (select 1 from r5aspectpoints a2                                  
where a2.apo_object = <equipcode> and a2.apo_object_org = <equiporg>                                  
and a2.apo_point = a.apo_point                                  
and a2.apo_pointtype = a.apo_pointtype)))
