Unable to call stored procedure in stored procedure

I have three stored procedures A, B, C

and the definition of A is similar to

StoredProcedure A
As 
Begin

--Some Stuff

Exec DBO.B [Derived Conitions]
Exec DBO.C [Derived Conitions]

END

but whenever I tried to execute stored procedure A, parsing time gave waring;

Module "A" depends on the missing object "B". The module will still be created; however, it cannot work successfully until the object exists.
Module "A" depends on the missing object "C". The module will still be created; however, it cannot work successfully until the object exists.

At run time, it throws an exception

Could not find stored procedure "dbo.B".
Could not find dbo.C stored procedure.

, .

+4
1

, , SP. 1 SP .

, / , B C.

SP .

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DerivedProcedures]
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Temporary table used to store results from SP1
    DECLARE @Results_ForStoredProcedure1 TABLE 
    (
        [SPID] INT, 
        [Status] NVARCHAR(50), 
        [Login] NVARCHAR(50), 
        [HostName] NVARCHAR(50), 
        [BlkBy] NVARCHAR(5), 
        [DBName] NVARCHAR(50),
        [Commad]  NVARCHAR(50),
        [CPUTime] INT, 
        [DiskIO] INT,
        [LastBatch] NVARCHAR(50),
        [ProgramName] NVARCHAR(50),
        [SPID2] INT,
        [RequestId] INT
    )

    -- Execute SP1
    INSERT INTO @Results_ForStoredProcedure1 
    EXEC sp_who2

    -- Temporary table to store the results from SP2
    DECLARE @Results_ForStoredProcedure2 TABLE 
    (
        [DatabaseName] NVARCHAR(50),
        [DatabaseSize] INT,
        [Remarks] NVARCHAR(50)
    )

    -- Execute SP2
    INSERT INTO @Results_ForStoredProcedure2
    EXEC sp_databases 

    -- do something with both SP results
    SELECT DISTINCT SP2.* 
    FROM @Results_ForStoredProcedure1 AS SP1
        INNER JOIN @Results_ForStoredProcedure2 AS SP2 ON SP2.DatabaseName = SP1.DBName
    WHERE SP1.DBName IS NOT NULL



END
GO

-- TEST
EXECUTE [dbo].[DerivedProcedures]
+1

All Articles