
select
p.per_code as employee, p.per_desc as employeedesc, p.per_mrc as department, p.per_trade as trade
from   r5userorganization u, r5personnel p where
p.per_notused = '-'  and per_code <> '*'
and  p.per_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  (per_mrc IN( SELECT dse_mrc FROM
r5departmentsecurity WHERE dse_user =<parameter.r5user> AND
dse_mrc = per_mrc AND coalesce(dse_readonly, '-') = '-'))))
ORDER BY p.per_code
