SQL Server Execute Stored Procedure from Another Stored Procedure with Parameters

3 Comments | 795 Views | Post by: Admin | Tags: SQL Server Execute Stored Procedure from Another Stored Procedure with Parameters


SQL Server Execute Stored Procedure from Another Stored Procedure with Parameters


Step 1: Open MS-SQL Server

Step 2: Select a database

Step 3: Create first Stored Procedure with the following codes:-

-- www.sourcecodehub.com ---

 --- First Stored Procedure
CREATE PROCEDURE sp1
@tempid INT,
@tempname varchar(50)
AS
BEGIN
DECLARE @temp1 TABLE (Id INT, Name VARCHAR(50), Location VARCHAR(50))
INSERT INTO @temp1 (Id, Name, Location)
VALUES(1,'raja','india'),
(2,'Rohan','UK'),
(3,'Satu','Nepal')
SELECT * FROM @temp1 WHERE Id=@tempid and Name=@tempname
END

Step 3: Create second Stored Procedure which will call first Stored Prodedure with the following codes:-

-- www.sourcecodehub.com ---
 --- Second Stored Procedure
CREATE PROCEDURE SAMPLE2
@id INT,
@name varchar(50)
AS
BEGIN
-- Calling First Procedure From Second Procedure
EXEC sp1 @tempid=@id, @tempname=@name
END

HOW TO USE:-

EXEC SAMPLE2 @id=1, @name='raja'


Post Comments

if you have some suggestion, question, request on SQL Server Execute Stored Procedure from Another Stored Procedure with Parameters.

Please use the comment box to express your views.

 

Comments:

loading...