Reputation: 251
I have stored procedure A and want to call store procedure B from A by passing a @mydate
parameter. Stored procedure B will return a rowset which I can further use in procedure A.
I researched this on Google but did not find anything without using a temporary table. Is there an easy way to get this without a temp table.
P.S.: I tried to get this done using stored procedure as A and a function as B easily. But want to know if I can get it done only by using stored procedures.
Upvotes: 25
Views: 122595
Reputation: 89
You can call Stored Procedure like this inside Stored Procedure B.
CREATE PROCEDURE spA
@myDate DATETIME
AS
EXEC spB @myDate
RETURN 0
Upvotes: 5
Reputation: 3435
Create PROCEDURE Stored_Procedure_Name_2
(
@param1 int = 5 ,
@param2 varchar(max),
@param3 varchar(max)
)
AS
DECLARE @Table TABLE
(
/*TABLE DEFINITION*/
id int,
name varchar(max),
address varchar(max)
)
INSERT INTO @Table
EXEC Stored_Procedure_Name_1 @param1 , @param2 = 'Raju' ,@param3 =@param3
SELECT id ,name ,address FROM @Table
Upvotes: 17
Reputation: 3108
You can create table variable instead of tamp table in procedure A and execute procedure B and insert into temp table by below query.
DECLARE @T TABLE
(
TABLE DEFINITION
)
.
.
.
INSERT INTO @T
EXEC B @MYDATE
and you continue operation.
Upvotes: 1
Reputation: 312
You can call a stored procedure from another stored procedure by using the EXECUTE command.
Say your procedure is X. Then in X you can use
EXECUTE PROCEDURE Y () RETURNING_VALUES RESULT;"
Upvotes: -2
Reputation: 6054
You can just call the Execute command.
EXEC spDoSomthing @myDate
Edit:
Since you want to return data..that's a little harder. You can use user defined functions instead that return data.
Upvotes: 9