开发者

Catch/Work with/Handle multiple datasets in a Stored Procedure from another Stored Procedure

Is it possible to work with the returned datasets from a stored procedure? Basically I have a stored procedure (lets call it SP_1) and it cal开发者_C百科ls another stored procedure (lets call it SP_2). SP_2 has 5 or so select statements. What I want to do is handle each select statement within SP_1. Basically to manipulate the data or whatever, but I do not know how to get it.

Let me show what im doing and that may make things clearer

CREATE PROCEDURE [dbo].[usp_1]
AS
exec usp_2
//How do I store the multiple select statements results in this stored proc?


In order to work, all the SELECTs within SP_2 will need to return the same number of compatible columns. If one returns 2 columns, another returns 5, and another returns 10, then it won't work.

If each SELECT does return the same number of columns, and the datatypes are consistent then you should be good to go using this approach in SP_1

CREATE TABLE #test (Col1 VARCHAR(10), Col2 VARCHAR(10))
INSERT #test
EXECUTE SP2 -- all resultsets return 2 VARCHAR columns
-- Now use #test which should contain all the combined results from SP2

However, if they all return different columns then you can't do it. You'd need to break each individual select into it's own sproc and call each one independently. SP2 would change to call those sub sprocs too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜