title: Using query export SQL Server 2008 table to Excel Sheet
body: <p>How to export sql server table data to excel sheet. </p>
  
  <pre><code> insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
  'Excel 12.0;Database=D:\Book1.xlsx;', 
  'SELECT * FROM [SheetName$]') select TOP 5 CustomerID from Customers
  </code></pre>
  
  <p>I used the above query but it shows following error</p>
  
  <blockquote>
    <p>Msg 7308, Level 16, State 1, Line 1 OLE DB provider
    'Microsoft.ACE.OLEDB.12.0' cannot be used for distributed queries
    because the provider is configured to run in single-threaded apartment
    mode.</p>
  </blockquote>