Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate list of employees and managers from AD
    primarykey
    data
    text
    <p>I have a table of employees and their managers:</p> <pre><code>-- Show the contents of the table SELECT * FROM ActiveDirectory.dbo.ADUser Last First ManagerDN Johnson Brent CN=Jones\, Bob,OU=IT Poleman Debbie CN=Jones\, Bob,OU=IT Kismain Lenni CN=Jones\, Bob,OU=IT Braiswool Marc CN=Jones\, Bob,OU=IT Garpial Pat CN=Johnson\, Brent,OU=IT McKinnis Laurie CN=Kismain\, Lenni,OU=IT Thomason Maddy CN=Poleman\, Debbie,OU=IT Dodgers Kevin CN=Thomason\, Maddy,OU=IT </code></pre> <p>I would like to create a list of employees, their managers, and their managers. For simplicity, assume there can be 3 levels:</p> <pre><code>LastName FirstName ManagerDN3 ManagerDN2 ManagerDN1 CN=Braiswool\, Marc,OU=IT CN=Jones\, Bob,OU=IT CN=Garpial\, Pat,OU=IT CN=Johnson\, Brent,OU=IT CN=Jones\, Bob,OU=IT CN=McKinnis\,Laurie,OU=IT CN=Kismain\, Lenni,OU=IT CN=Jones\, Bob,OU=IT CN=Thomason\, Maddy,OU=IT CN=Poleman\, Debbie,OU=IT CN=Jones\, Bob,OU=IT Dodgers Kevin CN=Thomason\, Maddy,OU=IT CN=Poleman\, Debbie,OU=IT CN=Jones\, Bob,OU=IT </code></pre> <p>Here is the code to create and populate the tables:</p> <pre><code>-- Create the ADUser table CREATE TABLE [dbo].[ADUser]( [Last] [nvarchar](50) NOT NULL, [First] [nvarchar](50) NOT NULL, [ManagerDN] [nvarchar](50) NOT NULL ) -- Populate the ADUser table INSERT INTO [ActiveDirectory].[dbo].[ADUser] ([Last] ,[First] ,[ManagerDN]) SELECT 'Johnson','Brent','CN=Jones\, Bob,OU=IT' UNION ALL SELECT 'Poleman','Debbie','CN=Jones\, Bob,OU=IT' UNION ALL SELECT 'Kismain','Lenni','CN=Jones\, Bob,OU=IT' UNION ALL SELECT 'Braiswool','Marc','CN=Jones\, Bob,OU=IT' UNION ALL SELECT 'Garpial','Pat','CN=Johnson\, Brent,OU=IT' UNION ALL SELECT 'McKinnis','Laurie','CN=Kismain\, Lenni,OU=IT' UNION ALL SELECT 'Thomason','Maddy','CN=Poleman\, Debbie,OU=IT' UNION ALL SELECT 'Dodgers','Kevin','CN=Thomason\, Maddy,OU=IT' </code></pre> <p>And then I can query each of the columns:</p> <pre><code>-- Show the Level2 Managers (ManagerDN2) SELECT Last, First, ManagerDN FROM dbo.ADUser WHERE ManagerDN = 'CN=Jones\, Bob,OU=IT' -- Show the Level3 Managers (ManagerDN3) SELECT Last, First, ManagerDN FROM dbo.ADUser WHERE ManagerDN IN ( SELECT 'CN=' + Last + '\, ' + First + ',OU=IT' FROM dbo.ADUser WHERE ManagerDN = 'CN=Jones\, Bob,OU=IT' ) -- Show the Employees SELECT Last, First, ManagerDN FROM dbo.ADUser WHERE ManagerDN IN ( SELECT 'CN=' + Last + '\, ' + First + ',OU=IT' FROM dbo.ADUser WHERE ManagerDN IN ( SELECT 'CN=' + Last + '\, ' + First + ',OU=IT' FROM dbo.ADUser WHERE ManagerDN = 'CN=Jones\, Bob,OU=IT' ) ) </code></pre> <p>How do I efficiently create the list of employees and their managers and their managers</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload