SELECT
lv3_code AS code,
lv3_desc AS description,
lv3_org AS organization,
lv3_level1 AS level1,
lv3_level1_org AS level1org,
lv3_level2 AS level2,
lv3_level2_org AS level2org
FROM r5level3
WHERE lv3_rstatus IN ( 'B', 'C', 'CIR', 'CRR', 'I' )
AND lv3_notused = '-'
AND COALESCE( lv3_level1, 'x' ) = COALESCE( <param.level1>, lv3_level1, 'x' )
AND COALESCE( lv3_level1_org, 'x' ) = COALESCE( <param.level1_org>, lv3_level1_org, 'x' )
AND COALESCE( lv3_level2, 'x' ) = COALESCE( <param.level2>, lv3_level2, 'x' )
AND COALESCE( lv3_level2_org, 'x' ) = COALESCE( <param.level2_org>, lv3_level2_org, 'x' )
AND EXISTS ( SELECT 1 FROM r5userorganization WHERE uog_org = lv3_org AND uog_user = <parameter.r5user> AND ( uog_common  = '+' OR uog_org = <control.org> ) )

