SELECT
p.per_code AS personcode,
p.per_desc AS persondescription,
p.per_emailaddress AS emailaddress,
p.per_mobilephoneno AS phone
FROM   r5userorganization u, r5personnel p  WHERE
IFNULL(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, '-') = '-')))) AND p.per_emailaddress IS NOT NULL
