2013-08-29 88 views
0

如何將sql server表格數據導出到Excel工作表。使用查詢導出SQL Server 2008表格到Excel工作表

insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
'Excel 12.0;Database=D:\Book1.xlsx;', 
'SELECT * FROM [SheetName$]') select TOP 5 CustomerID from Customers 

我用了上面的查詢,但它顯示了以下錯誤

消息7308,級別16,狀態1,行1 OLE DB提供程序 'Microsoft.ACE.OLEDB.12.0' 不能用對於分佈式查詢 ,因爲提供程序被配置爲在單線程公寓 模式下運行。

+0

的解決方案是在http://blog.sqlauthority.com/2010/11/03/sql-server-fix- error-ms-jet-oledb-4-0-can-be-used-for-distributed-queries-because-the-provider-is-used-to-run-in-apartment-mode/ – VIJAY

+0

我也試過了。即使它顯示相同的錯誤。 – Golda

回答

1

我已經找到了解決辦法

sp_configure 'show advanced options', 1; 
GO 
RECONFIGURE; 
GO 
sp_configure 'Ad Hoc Distributed Queries', 1; 
GO 
RECONFIGURE; 
GO 
EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1 
GO  
EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1 
GO 
insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
'Excel 12.0;Database=D:\Book1.xls;', 
'SELECT * FROM [Sheet1$]') select TOP 5 CustomerID from Customers 

它的做工精細