select 
s.stw_desc as description,
s.stw_code as standardwo,
s.stw_org as standardwoog
FROM r5standworks s, r5userorganization u WHERE  
 (( s.stw_obclass IS NULL AND s.stw_object IS NULL ) OR        
 (( <param.equipclass> IS NOT NULL AND <param.category> IS NULL ) AND 
 (( s.stw_obclass = <param.equipclass> AND s.stw_obclass_org = <param.equipclassorg> ) 
 AND s.stw_object IS NULL )) OR        (( <param.equipclass> IS NOT NULL AND <param.category> IS NOT NULL ) 
 AND ( s.stw_obclass = <param.equipclass> AND s.stw_obclass_org = <param.equipclassorg> AND 
 IFNULL(s.stw_object, <param.category>) =<param.category> ))) AND  coalesce(s.stw_notused,'-')='-' AND 
 s.stw_type in ('SWO','PSWO') AND  s.stw_org = u.uog_org   AND  u.uog_user = <parameter.r5user>  AND  
 (u.uog_common = '+' or u.uog_org = <control.org>)  
 
