从LDAP查询中提取管理器名称[从LDAP查询创建的SQL视图]

时间:2015-04-23 10:02:50

标签: sql sql-server active-directory ldap

我已设置此视图:

SELECT     
displayname AS [Full Name], manager, department, company, 
physicaldeliveryofficename, mail AS [E-Mail Address], telephonenumber
FROM         
OPENQUERY(ADSI, 
'SELECT 
sAMAccountName, givenName, company, 
physicaldeliveryofficename, sn, displayname, mail, telephonenumber,department, useraccountcontrol, manager 
FROM 
''LDAP://DC=blah,DC=local''
WHERE 
objectClass = ''User'' and objectCategory = ''Person''') AS derivedtbl_1
WHERE     
(useraccountcontrol & 2 = 0)

使用SQL Server从ActiveDirectory中提取员工数据但是管理器字段包含所有映射:CN,OU,DC,如下所示:

CN = blah blah,OU = blah,OU = blah TGP,DC = blah,DC = local

而我真正想要的只是他们的全名(CN。)

我想要两件事:

  1. 从视图中拉出CN。

  2. 获取经理的电子邮件。

  3. 该视图使用以下字段:

    displayname,manager,department,company,physicaldeliveryofficename,mail

    但是,我希望最终结果是在其末尾添加额外的字段管理器电子邮件,以完成整个数据集。

    如上所述,所有信息的视图已成功创建,因此可以在SQL端完成,但我很难找到实现我想要的方法。

    提前致谢!

    编辑:添加了查看代码

1 个答案:

答案 0 :(得分:0)

旧问题,但对于正在寻找解决方案的其他人。通过一些SUBSTRING工作拉了CN。 SUBSTRING将抓取第一个等号和第一个逗号之间的所有内容,从而解决了第一个问题:

def function1(): # declares function 2 as printing hello
    print("hello")

def function2(): # declares function 2 as printing bye
    print("bye")

def function3(): # declares function 3 as returning "Hi again", which is printed upon it being called.
    return "Hi again"

function1() # will print hello
function2() # will print bye

print(function3()) # will return the value "Hi again" and then print it