Call SP from another SP with result set
I have a stored procedure in which I have called another stored procedure [Let say I have parent stored procedure which is calling child SP]. Child stored procedure have a result set which have almost 10,000 records. How can I get it in the parent stored procedure?
Parent SP
(
Student INT
Teacher INT
Name Var开发者_Python百科char
)
Child SP [Get Student specific activities] Student
-- Result Set of Child SP needed Here
-- End of Parent SP
One was is to use INSERT... EXECUTE...
Within the parent stored procedure, have something like:
CREATE TABLE #Temp (StudentId int null, <Other columns as required>)
INSERT #Temp
EXECUTE ChildSP
The (single!) data set returned by the child SP must match the table structure of #Temp.
You would store the results of your child stored procedure into a temp table and access those records in the parent stored procedure by selecting from the temp table.
精彩评论