Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to import an SQL stored Procedure into Excel

Status
Not open for further replies.

Peager

Programmer
May 27, 2003
140
0
0
US
I need to 'pull' the results of an SQL stored procedure (returns a table) into Excel. Can someone point me in the right direction? SQL 2005 * Excel 2003 SP2.
 
I believe you can use DTS to execute the SP and export to Excel.

Sam
 
you can use a standard ADO Recordset to return the output of the SP into Excel.

This is probably better asked on the VBA forum, but in any case you will need to add a reference to MDAC 2.x (2.8 or greater if possible), and then you can use a ADO command object associated with a ADO recordset object to execute and retrieve the SP results.

Depending on your version of Excel you may have a "copyfromrecordset" method from within Excel. If you dont then you can just loop normally through the recordset.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 


Hi,

Unless you are a total query novice, I'd discard the stored procedure that would return an entire table.

Rather query your SQL Server directly via MA Query -- Data/Get External Data... Return ONLY the subset of data that you really need. Add parameters to return different resordset.

Once you have added a QueryTable to an Excel sheet, all you need do is Data/Refresh Data

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top