Create your first Stored Procedure which returns a table
The code for the stored procedure might look like this-
CREATE PROCEDURE dbo.GetDetailByFname
(
@Fname nvarchar(50)
)
AS
Select pid, Fname, Mname, Lname from Personal where fname=@Fname;
If you call this stored Procedure as
EXEC dbo.GetPeopleByLastName @FName = 'Rahul'
Result will look like
pid FName MName LNAme
uniquidentifier Rahul . Singh
uniquidentifier Rahul abc Bachchan
-------- Rahul XYZ Rathod
If you want to use this result you'll need a place to store it, that is Temporary Tables . That code might look something like this-
CREATE PROCEDURE dbo.CountByLname
As
DECLARE @Personal TABLE (
Pid uniqueidentifier,
FName NVARCHAR(50),
Mname NVARCHAR(50),
LName NVARCHAR(50)
)
INSERT @Personal (Pid, FName, Mname, LName)
EXEC dbo.GetDetailByFname @Fname = 'Rahul'
SELECT COUNT(*) AS Counts FROM @Personal
If you call this stored Procedure as
EXEC CountByLname
Result will look like
Counts
3
This is how we can call 1st procedure or function that returns a table in 2nd stored procedure or function
If you want Integer as return type
Try this one as 1st stored procedure
CREATE PROCEDURE dbo.GetDetailByFname
(
@Fname nvarchar(50),
@Age INT OUTPUT
)
AS
Select Age from Personal where Fname=’Rahul’
Then use this output variable in 2nd stored procedure
I hope it's helped you..
Regards,
jayant