Wednesday, 21 November 2018

MSSQL - How to excecute stored procedure inside another stored procedure and assign result to a sql variable

Watch this example on YouTube


1. First stored proc

CREATE PROCEDURE Sproc1
    @ID int
AS
BEGIN
    SET NOCOUNT ON;
    SELECT Count(*) From Product Where ProductID > @ID
END
GO

2. Second stored procedure

Alter PROCEDURE SProc2
AS
BEGIN
    SET NOCOUNT ON;
    Declare @MyID int = 2
    Declare @Result int
    Exec @Result = SProc1 @MyID
END

3. Execute stored procedure

Exec SProc2

No comments:

Post a Comment