SELECT /* Fix for bug # 5024093 */
msite.msite_id,
msite.org_id
FROM ( -- It get all the iStore sites attached to particular Operating Unit(OU)
SELECT msite_id,
TO_NUMBER(fnd_profile.value_specific ('ORG_ID',
-99999,
responsibility_id,
application_id
)
) org_id
FROM IBE.IBE_MSITE_RESPS_B
UNION ALL -- This union all is used for external sites attached to an OU
SELECT msite_id,
default_org_id
FROM IBE.IBE_MSITES_B
WHERE site_type = 'E') msite -- E is for External Site
WHERE org_id IS NOT NULL
GROUP BY msite.msite_id,
msite.org_id