将sql查询结果导出为ex​​cel文件

我将查询结果保存到SQL Server 2008中的表my_table中,然后希望将表中的数据插入到Excel 2007文件中。 以下是我正在使用的查询 –

 INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\testing.xls;', 'SELECT Name, Date FROM [Sheet1$]') SELECT a, b FROM my_table GO 

它显示以下错误

 Msg 7308, Level 16, State 1, Line 1 OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode. 

我怎样才能得到这个固定的? PS Ad Hoc分布式查询似乎在我的系统上启用。 在这里输入图像说明

你需要在查询之前运行它:

 EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'AllowInProcess', 1 GO EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'DynamicParameters', 1 GO 

在你的查询设置这个值为0后,如果你需要的话。 如果运行64位服务器,则需要使用Microsoft.ACE.OLEDB.12.0