select DISTINCT NCF_OBJECT as equipmentcode, NCF_OBJECT_ORG as equiporganization, OBJ_DESC as equipmentdesc
FROM   r5mrcs m, r5objects o, r5nonconformities, r5organization
WHERE  COALESCE(o.obj_notused, '-') <> '+'
AND    o.obj_rstatus in ('B', 'C', 'CIR', 'CRR', 'I')
AND    o.obj_code <> '*'
AND    org_code = ncf_object_org
AND    ncf_object = o.obj_code
AND    ncf_object_org = o.obj_org
AND    ncf_rstatus = 'O'
AND NOT EXISTS( SELECT 'x'
          FROM   r5nonconformobservations
          WHERE  ncf_code = nco_code
          AND    nco_workorder = <param.workordernum>)
          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, '-') = '-'))))
