使用查询导出SQL Server 2008表到Excel工作表

时间:2013-08-29 09:15:30

标签: sql-server excel export

如何将sql server表数据导出到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

我使用了上述查询但显示以下错误

  

Msg 7308,Level 16,State 1,Line 1 OLE DB提供程序   'Microsoft.ACE.OLEDB.12.0'不能用于分布式查询   因为提供程序配置为在单线程单元中运行   模式。

1 个答案:

答案 0 :(得分: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

工作正常

相关问题