I need to execute a stored procedure within another stored procedure and take results of the internal stored procedure to use in the external stored procedure.
Simply like follows.
SP1
CREATE PROCEDURE spExternal
AS
BEGIN
SET NOCOUNT ON;
DECLARE @intInternalResult INT
SET intInternalResult= EXEC spInternal
END
SP Internal
CREATE PROCEDURE spInternal
AS
BEGIN
SET NOCOUNT ON;
SELECT 1+2
END
My Friend,
You can not assign value to a variable which you are not returning. You can write a function to do job of stored procedure spInternal which will return a value. Else you can do it this way:
And one more thing, next time don’t forget to put @ in front of a variable.