How to execute a stored procedure inside another stored procedure?
How to execute a stored procedure inside another stored procedure? In this article I'm going to explain how to execute stored procedure from another stored procedure in Sql. Herewith I have explained step by step process to calling stored procedure.
How to execute a stored procedure inside another stored procedure? In this article I'm going to explain how to execute stored procedure from another stored procedure in Sql. Herewith I have explained step by step process to calling stored procedure.
To create sample(Emp) table
Create table Emp(EmpId int,EmpName Varchar(max))
Insert values into Sample(emp) table
Insert into Emp values(1,'rengan')
Insert into Emp values(11,'rengan1')
Insert into Emp values(111,'rengan111')
Insert into Emp values(122,'kumar')
Create procedure to select records based on EmployeeId from Sample table(emp).
Without Inner Stored proceudre.
Create proc SampleProcedure(@EmpID int)
as
begin
select * from Emp where EmpId =@EmpID
end
To run Stored proceudre
EXEC SampleProcedure 1
WithInner Stored procedure.
Create proc MainSampleProcedure(@EmpID int)
as
begin
Declare @Palert varchar(max)
Exec InnerSampleProcedure @EmpID,@Palert output----Calling Another Stored procedure from main Stored procedure. EXEC is excute command
select * from Emp where EmpName =@Palert
end
To Run Stored Procedure
EXEC MainSampleProcedure 1
Inner Procedure.
Create proc InnerSampleProcedure(@EmpID int,@Palert varchar(max) output)
as
begin
select @Palert=EmpName from Emp where EmpId =@EmpID
end
No need to run this Stored procedure.