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. Therefore, you may get a different result when you invoke the view at a later time.

The following code sample shows how to create a view.

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

Use the following code to invoke a view.

SELECT * from viewADUsers

Creating a Heterogeneous Join between SQL Server and Active Directory