select 
obj_category as category,
obj_criticality as criticality,
o.obj_mrc as department,
obj_person as equipassignedto,
O.OBJ_CLASS as equipclass,
O.OBJ_CLASS_ORG as equipclassorg,
obj_costcode as equipcostcode,
o.obj_code as equipmentcode,
o.OBJ_DESC as equipmentdesc,
O.OBJ_OBTYPE as equipmenttype,
o.obj_org as equiporganization,
o.obj_primaryuom as meteruom,
o.obj_safety as equipsafety,
obj_location as defaultlocation, -- Additional Validation needed
obj_location_org as defaultlocationorg -- Additional Validation needed
from   r5userorganization u, r5mrcs m, r5objects o
where IFNULL(o.obj_notused, '-') <> '+' 
and o.obj_rstatus in ('B', 'C', 'CIR', 'CRR', 'I') 
and o.obj_obrtype NOT IN ('C', 'I')  
and o.obj_code <> '*' 
and o.obj_mrc = m.mrc_code  
and o.obj_org = u.uog_org 
and u.uog_user = <parameter.r5user> 
and  ( u.uog_common = '+' or u.uog_org = <control.org>) 
AND (<param.bypassdeptsecurity> = 'true' OR (<parameter.deptsec> ='OFF' OR 
(obj_mrc IN( SELECT dse_mrc FROM r5departmentsecurity WHERE dse_user =<parameter.r5user> AND dse_mrc = obj_mrc AND coalesce(dse_readonly, '-') = '-'))))
