Hi @all,I've got a table/view which contains the organizational Units structure of the Active Directory. With the following T-SQL Statement I get the hierarchy which works fine:WITH cte AS ( SELECT OU_GUID , OU_Name , OU_ParentGUID , 1 OULevel FROM dbo.V_DIM_01_OrganizationalUnits WHERE OU_ParentGUID = '' UNION ALL SELECT c.OU_GUID , c.OU_Name , c.OU_ParentGUID , p.OULevel + 1 FROM dbo.V_DIM_01_OrganizationalUnits c JOIN cte p ON p.OU_GUID = c.OU_ParentGUID)SELECT * FROM cte
The structure could be - "OU" => "US" => "User" - "OU" => "MX" => "User"- "OU" => "DE" => "User" - "OU" => "PL" => "User"Now I have an additional column "region" which I added via the view V_DIM_01_OrganizationalUnits.SELECT [OU_GUID] ,[OU_ParentGUID] ,[OU_Path] ,[OU_Name] ,CASE WHEN upper([OU_Name]) IN ('CH','CZ','DE','ES','FR','GB','IT','PL','RS','RU','SE','TR') THEN 'EMEA' WHEN upper([OU_Name]) IN ('BR','MX','US') THEN 'AMERICAS' WHEN upper([OU_Name]) IN ('AU','CN','IN','JP','MY','SG','TH') THEN 'APAC' END Region FROM [T_DIM_OrganizationalUnits]
The future structure should be - "OU" => "Americas" => "US" => "User"- "OU" => "Americas" => "MX" => "User"- "OU" => "EMEA" => "DE" => "User"- "OU" => "EMEA" => "PL" => "User"How can I include the "region" into my statement as it is actually not a member of the real hierarchy. Thanks!