I am using multiple stored procedures (return type tabular only 1 row in result) in a master stored procedure:
CREATE PROCEDURE [dbo].[MAster_sp]
(@param INT)
AS
BEGIN
EXEC [dbo].[sp1] @param
EXEC [dbo].[sp2] @param
.
.
END
Then output is like this
sp1 output:
Male_Emp_Count Female_Emp_Count
-------------- ----------------
1 0
Sp2 output:
empId empJoiningDate
----------- --------------
17 2019-07-10
. . .
I want these results in single dataset row as a response to my API.
When I tried inserting into a table variable, I get an error
An INSERT EXEC statement cannot be nested
What is this error and how to handle this error? I tried google but no relevant article or info that helps me to understand this issue.
CREATE PROCEDURE [dbo].[MAster_sp]
(@param INT)
AS
BEGIN
CREATE TABLE #tempMainTbl
(
c1 INT NULL,
c2 INT NULL,
c3 INT NULL,
c4 INT NULL,
c5 INT NULL
)
INSERT INTO #tempMainTbl (c1, c2, c3)
EXEC [dbo].[sp1] @param
EXEC [dbo].[sp2] @param
.
.
SELECT * from #tempMainTbl
END
Error:
Msg 8164, Level 16, State 1, Procedure dbo.[sp1], Line 33 [Batch Start Line 8]
An INSERT EXEC statement cannot be nested.
Actual result that I got now:
sp1 Output
Male_Emp_Count Female_Emp_Count
-------------- ----------------
1 0
Sp2 Output
empId empJoiningDate
----------- --------------
17 2019-07-10
Expected result:
Male_Emp_Count Female_Emp_Count empId empJoiningDate
-------------- ---------------- ----- --------------
1 0 17 2019-07-10
All stored procedures output in single row.