Sammy
Sammy

Reputation: 808

Saving results of a SQL Server stored procedure to an Excel format programatically

I need to save the results of a SQL Server stored procedure into an Excel file. How can I do this programatically, as part of the same stored procedure - preferably as the last step of the stored procedure?

Please note that I do not have a separate web application. I want to perform this save functionality to Excel, as part of the stored procedure itself.

Upvotes: 1

Views: 381

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269563

This is a bit long for a comment.

My first suggestion is to save the data as a delimited file, which can easily be imported into Excel. This should be fine for archival purposes, for instance, or for sending the results around by email.

The next suggestion is to save the results in a table, and to have a data connection to that table. You can then have a query in the Excel file that automatically refreshes the data. This is handy for having special formatting and charts in the Excel file.

Another option is to use openrowset() to directly write to an Excel file. The process would often be something like copying a template file to a new location and then writing the data to it.

The best method really depends on what you want to do with the results.

Upvotes: 1

Related Questions