SELECT 
    ou.OU_code,
    ou.Organizational_unit_ID,
    ou.OU_short_name,
    ou.OU_pharmacy_code,
    ou.OU_subsidiary
FROM [Arizona].[dbo].[Bmc_application_key] [bak] WITH (NOLOCK)
    JOIN [Arizona].[dbo].[Bmc_application_default] [bad] WITH (NOLOCK)
        ON [bad].[BAPD_bmc_application_key] = [bak].[Bmc_application_key_ID]
    JOIN [Arizona].[dbo].[Organizational_unit] OUA WITH (NOLOCK)
        ON OUA.[Organizational_unit_ID] = [bad].[BAPD_value]
    JOIN [Arizona].[dbo].[Organizational_unit] [ou] WITH(NOLOCK)
        ON [ou].[OU_code] = [OUA].[OU_code]
WHERE [bak].[BAPK_key] = 'cvCurrentOrganizationalUnit'

SELECT TOP 100  l.AOUL_source_key, ou.* 
FROM ArizonaREP.dbo.Address a
    JOIN ArizonaREP.[dbo].[Address_OU_link] l ON l.AOUL_address = a.Address_GUID
    JOIN ArizonaREP.dbo.Organizational_unit ou ON ou.Organizational_unit_GUID = a.AD_creation_OU 
        OR ou.Organizational_unit_GUID = a.AD_update_OU
WHERE AD_sex <> 4
AND ad_name ='WINKELMANN Martin'
