SELECT
lv2_code AS code,
lv2_desc AS description,
lv2_org AS organization,
lv2_level1 AS level1,
lv2_level1_org AS level1org
FROM r5level2
WHERE lv2_rstatus IN ( 'B', 'C', 'CIR', 'CRR', 'I' )
AND lv2_notused = '-'
AND COALESCE( lv2_level1, 'x' ) = COALESCE( <param.level1>, lv2_level1, 'x' )
AND COALESCE( lv2_level1_org, 'x' ) = COALESCE( <param.level1_org>, lv2_level1_org, 'x' )
AND EXISTS ( SELECT 1 FROM r5userorganization WHERE uog_org = lv2_org AND uog_user = <parameter.r5user> AND ( uog_common  = '+' OR uog_org = <control.org> ) )
