SQL Server 2016 Hosting – HostForLIFE.eu :: Calling/Executing SQL Stored Procedure from Another Stored Procedure
|In this blog I will explain one of the major application in stored procedure that will execute one procedure from another procedure with parameters in SQL Server
Let’s start with creating stored procedure.
Here’s the query for creating the first procedure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
create procedure Sp_insert ( @ID int , @TempName varchar(max) ) as begin Declare @SampleTable Table(id int, Name varchar(max)) Insert into @SampleTable(id,Name)values(@ID,@TempName) select*from @SampleTable end My Second Stored procedure: create procedure Sp_Call ( @SID int, @Name varchar(max) ) as begin exec Sp_insert @ID=@SID,@TempName=@Name end From t |
In the above query you can notice that we are calling first stored procedure Sp_insert and passing the parameter @ID and @TempName to it.
Now execute the second procedure using the following query. It will call the first procedure and return the result.
1 |
Exec Sp_Call @SID=1,@Name='Peter' |