This is a SQL Server sample solution to this problem, using one stored procedure to call one of two others, depending on the value of a parameter passed to the original sp. It is possible to chain numerous sp's together like this. The key is that the result set always has the same structure, and always comes from the original stored procedure, because of the final select statement.
This can be an effective way to reuse complex code in stored procedures - and reduce maintenance by packaging code in stored procedure "modules" that you call multiple times.
CREATE PROCEDURE spForm2 @WhichSPDoICall varchar(50)
AS
SET NOCOUNT ON
--------------------------
CREATE TABLE #TempTable(
EmployeeID int NOT NULL,
StartDate datetime NULL,
TermDate datetime NULL)
--------------------------
IF @WhichSPDoICall = 'spForm2A'
--Populates the # table
EXECUTE spForm2A
ELSE IF @WhichSPDoICall = 'spForm2B
--Populates the # table with some other data instead
EXECUTE spForm2B
SELECT * FROM #TempTable
SET NOCOUNT OFF
-----End of procedure
and a typical called stored procedure would be like
CREATE PROCEDURE spForm2A
AS
SET NOCOUNT ON
--------------------------
--#TempTable has already been created in calling procedure
INSERT INTO #TempTable (EmployeeID, StartDate)
SELECT * FROM SomeTable
Malcolm Wynden
I'm for sale at
malcolm@wynden.net