title: How to import Active Directory data into a SQL Server table using query?
body: <pre><code>CREATE TABLE T_AD_Data
  (
      lab_sAMAccountName varchar(100),
      lab_displayName varchar(100),
      lab_department varchar(100),
      lab_physicalDeliveryOfficeName varchar(100), 
  );
  
  INSERT INTO T_AD_Data
     SELECT * 
     FROM OpenQuery (ADSI,  
                     'SELECT sAMAccountName, displayName, department, physicalDeliveryOfficeName 
                      FROM ''LDAP://lab.com/DC=lab,DC=com'' 
                      WHERE objectClass =  ''User'' ') AS tblADSI
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Msg 7330, level 16, state 2, Line 1<br>
    Cannot fetch a row from OLE DBprovider "ADSDSOObject" for linked server "ADSI"</p>
  </blockquote>