Directory Services

Creating and Executing a View

You can create a view for data obtained from Active Directory. Be aware that only the view definition is stored in SQL Server, and not the actual result set. So you can get a different result when you execute the view later. To create a view, type and execute the following code.

CREATE VIEW viewADUsers AS
SELECT * FROM OpenQuery( ADSI,'<LDAP://DC=Fabrikam,DC=com>;(&(objectCategory=Person)(objectClass=user));name, adspath,title;subtree')

To execute a view, type the following code.

SELECT * from viewADUsers