简体   繁体   English

如何使用openrowset函数导出到Excel

[英]How to export into Excel with openrowset function

I am trying to export a table into Excel through Openrowset command 我正在尝试通过Openrowset命令将表导出到Excel中

INSERT INTO OPENROWSET 
   ('Microsoft.ACE.OLEDB.12.0', 
   'Excel 12.0;Database=c:\Test.xls;','SELECT * FROM dbo.tablename')

I am getting an error : 我收到一个错误:

'incorrect syntax near )' ')附近的语法不正确'

If you want to export into an Excel: 如果要导出到Excel中:

You can use three common file formats to export SQL Server data to Excel: 您可以使用三种常见的文件格式将SQL Server数据导出到Excel:

  • Excel workbook ( XLS / XLSX file). Excel工作簿( XLS / XLSX文件)。

Note : Only SSIS (SQL Server Integration Services) supports exporting to Excel workbook. 注意:SSIS(SQL Server集成服务)支持导出到Excel工作簿。

Note : SQL Server Express Edition not allows to save a SSIS package so you can use this way only if you have SQL Server Standard or higher. 注意: SQL Server Express Edition不允许保存SSIS包,因此仅当您具有SQL Server Standard或更高版本时才可以使用此方式。

[Read this article :] SQL Server Export to Excel using SSIS . [阅读本文:] 使用SSIS将SQL Server导出到Excel


  • CSV file. CSV档案。

Microsoft Excel users can open CSV file the same way as a native Excel file. Microsoft Excel用户可以以与本机Excel文件相同的方式打开CSV文件。

So export to CSV files is suitable for most cases and you can use a simple command line utilities instead of SQL Server Integration Services. 因此,导出到CSV文件适合大多数情况,您可以使用简单的命令行实用程序代替SQL Server Integration Services。

The disadvantage of the export to Excel workbook or CSV file is that a user receives a new file every time and losts its changes. 导出到Excel工作簿或CSV文件的缺点是用户每次都会收到一个新文件,并且丢失其更改。

[Read this article :] SQL Server Export to Excel using bcp/sqlcmd and CSV . [阅读本文:] SQL Server使用bcp / sqlcmd和CSV导出到Excel


  • XML file. XML文件。

XML can be more suitable as a user can import XML file to an Excel workbook once and then refresh the data when get a new file. XML可能更适合,因为用户可以一次将XML文件导入Excel工作簿,然后在获取新文件时刷新数据。

[Read this article :] SQL Server Export to Excel using bcp/sqlcmd and XML . [阅读本文:] 使用bcp / sqlcmd和XML将SQL Server导出到Excel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM