Skip to content
Advertisement

Excel VBA – Stored Procedure (SQL Server)

I have a slight issue retrieving multiple recordsets (with column names) and pasting the data into an Excel sheet, like the image below

enter image description here

The VBA code that I have just retrieves the first recordset but not the rest

Any help will be much appreciated, thank you

Update

I added the below loop but still no luck

This is the stored procedure code:

Advertisement

Answer

The answer of S Meaden mentioning the GetNextRecordSet solves your issue having multiple recordsets as result of a stored proc.
The following code dumps all recordsets, including the field names, into a sheet (do not forget to cleanup the sheet first if you run it repeatedly).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement