Retrieve data from stored procedure which has multiple result sets

后端 未结 9 523
一个人的身影
一个人的身影 2020-11-30 08:47

Given a stored procedure in SQL Server which has multiple select statements, is there a way to work with those results separately while calling the procedure?

9条回答
  •  既然无缘
    2020-11-30 09:03

    While this does not appear to be supported natively in T-SQL, if using a CLR Stored Procedure is an option for you, then you should be able to create a Stored Procedure in your preferred .Net language that uses the SqlDataReader.NextResult() method to advance to the desired result set and then send the SqlDataReader back via the SqlPipe.Send(SqlDataReader) method. You would just need to pass in the SQL to execute and the desired result set as parameters to this proc.

    This would allow you to work with the proc as is, without modifying it to send back all or only one result set.

提交回复
热议问题