http://www.myexception.cn/sql-server/1011477.html
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject', 'adsdatasource'GO
CREATE VIEW temp
as
SELECT [NAME], ADsPath [DN], Company [comp]
FROM OPENQUERY( ADSI,
'SELECT Name, ADsPath, COMPANY
FROM ''LDAP://servername/ DC=AAAAAA,DC=com''
WHERE objectCategory = ''Person'' AND
objectClass = ''user''')
GO
Drop table test.dbo.ADDATA
GO
Select *
into test.dbo.ADDATA
from temp
GO
EXEC sp_dropserver 'ADSI'
GO
Drop view temp