Wednesday, May 24

Export a SQL Server 2005 table to an Excel file

I've been trying to implement an option on my application to export a database table from SQL Server 2005 to an excel .XLS file, with the name and location of the excel file specified by the user.

The best way I could come up with was to create an SSIS package to export the file using Tasks / Export Data on SQL Server and save this as a file. In my application I search and replace the name of the output file with the name specified by the user, save this as a new package and then run dtexec on the new package to create the Excel file.

Does anyone know if there is a better and more robust way of doing this?

1 comment:

Richard Jonas said...

I found a better way - here's how to do this