0

I am trying to export a table into Excel through Openrowset command

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 )'

shA.t
  • 16,580
  • 5
  • 54
  • 111
Shishir Kumar
  • 11
  • 1
  • 5

1 Answers1

0

If you want to export into an Excel:

You can use three common file formats to export SQL Server data to Excel:

  • Excel workbook (XLS/XLSX file).

Note : Only SSIS (SQL Server Integration Services) supports exporting to Excel workbook.

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.

[Read this article :] SQL Server Export to Excel using SSIS.


  • CSV file.

Microsoft Excel users can open CSV file the same way as a native Excel file.

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.

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.

[Read this article :] SQL Server Export to Excel using bcp/sqlcmd and CSV.


  • XML file.

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.

[Read this article :] SQL Server Export to Excel using bcp/sqlcmd and XML.

Community
  • 1
  • 1
shA.t
  • 16,580
  • 5
  • 54
  • 111