In this blog I will explain one of the major application in stored procedure that will execute one procedure from another procedure with parameters.
Let's start with creating stored procedure.
Here's the query for creating the first procedure:
- 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.
- Exec Sp_Call @SID=1,@Name='Arun'
The result: