Does a procedure exist to return metadata for all result sets in a stored procedure?
No and Yes.
There is no pure T-SQL means of accessing more than the first result set. Even OPENROWSET and OPENQUERY have the same limitation:
Although the query might return multiple result sets, OPEN(ROWSET|QUERY) returns only the first one.
For the record, I am neither saying nor implying that there is any common technical reason for this limitation. I am just pointing out that the limitation is not confined to
The only way to capture info -- result set meta-data and even the results -- for result sets 2 - n is via application code. You would first execute the queries / stored procedure(s) by using SqlCommand.ExecuteReader(CommandBehavior) with a CommandBehavior of
KeyInfo. Then, you can get the result set meta-data using the SqlDataReader.GetSchemaTable method, and calling the SqlDataReader.NextResult method to cycle through the result sets. Just keep in mind that while doing this via app code does not have the limitations of not working with Dynamic SQL and temporary tables, it does actually run the SQL code, and if you have DML statements and only want the result set meta-data without causing any data changes, then you will have to wrap the SQL you are testing in a
BEGIN TRAN /
The type of application can be a regular Windows App, Console App, Web App, etc, or it can even be a SQLCLR function / stored procedure.
With regards to doing this via SQLCLR, a stored procedure already exists that does what is described here. It is called DB_DescribeResultSets and is part of the SQL# library (which I am the author of, and while there is a Free version, DB_DescribeResultSets is only available in the Full version).