I have a stored procedure. This proc returns some data that needs to be put in an excel format. Is it possible to create a excel file to have the result of a select statement from the database? please help me out.

Thanks

If you're looking to have your stored procedure directly output Excel-formatted data, then no it can't be done. You could use CLR to do some object manipulation, but that's a real pain.

If you execute your stored procedure in SSMS, you can output to a grid, then right-click any header cell and save the results as a .CSV file (which Excel will pick up) but you can't specify special Excel formatting.

However, if you want to automate (as in, a batch job to output an Excel file) your best bet is to use SSIS to execute your stored proc and pump the results out to an Excel file. Or, if it's a onesy-twosy kind of thing, you could execute your stored procedure from Excel directly.

Hope this gives you some ideas. Good luck!

You can output to excel using OPENROWSET or bcp (with xp_cmdshell).

commented: Oh, yeah...forgot about that one... :) +7