select
p.par_condition conditioncode,p.par_uom uom,CASE p.par_byasset WHEN '+' THEN -1 ELSE 0 END trackbyasset,PAR_TRACKRTYPE
trackrtype,1 requestedqty,p.par_trackbycondition trackbycondition,p.par_parentpart parentpart,p.par_conditiontpl
conditiontemplatecode,p.par_conditiontpl_org partconditiontemplateorg,p.par_code partcode,p.par_desc description,p.par_org
partorganization,p.par_importance partimportance,p.par_materialtype partmaterialtype from  r5parts p left outer join r5partmfgs m on (m.mfp_part=p.par_code and m.mfp_part_org=p.par_org and
m.mfp_notused = '-') where exists (select 'X' from r5userorganization where uog_user= <parameter.r5user>
and uog_org = p.par_org and (uog_common='+' or uog_org = <control.org> )) and coalesce(p.par_notused,'-') <> '+'
and p.par_code <> '*' AND COALESCE( m.mfp_notused,'-') = '-' AND coalesce( <param.trackbycondition> , 'false') = 'false' or not
(p.par_parentpart is not null and  coalesce(p.par_trackbycondition,'-') = '+') order by partcode ASC, partorganization ASC
