How can I execute a stored procedure in Microsoft Excel and get all the data it returns?
feedback
|
|
This is a job for an ADODB connection in VBA. Here's a link with a sample code for a simple SELECT query, but this will handle stored procedures just as well. http://www.ozgrid.com/forum/showthread.php?t=83016&page=1 The key items are the need to declare an
Then move the data from your recordset ( | |||
|
feedback
|
|
I'm not sure about the latest incarnation of Excel, but in 2000 and 2003 all you could do was access a view and have it's data displayed on the excel sheet. The main advantage of a stored procedure would be the ability to parameterize the result, but for that you'd need some sort of UI, and you'd need a way to programmatically modify the query definition after it's first defined within excel. We didn't find a way to do this, but using views provided enough functionality for what we needed to do. | |||
|
feedback
|
|
This VBA is very similar to @Excellll's answer, and I've used it to good effect in my own work. Use this little utility function:
And then here's the big function (I apologize for the crummy-looking paragraph alignment):
Hope this helps. | |||
|
feedback
|