• amalanto (2/25/2010)


    Hi,

    I am using sql server 2005,In that we have one stored procedure A to call stored procedure B, which returns a set of records from a table. Then, I want stored procedure A to perform work on these records. How do I call stored procedure B from within stored procedure A?

    Thanks in advance.

    I think you can use this logic and try this works as the same way you asked B to A

    in the below Eg only one output has been given in your case you can use your records in the OUTPUT.

    USE AdventureWorks;

    GO

    IF OBJECT_ID ( 'Production.usp_GetList', 'P' ) IS NOT NULL

    DROP PROCEDURE Production.usp_GetList;

    GO

    CREATE PROCEDURE Production.usp_GetList @product varchar(40)

    , @maxprice money

    , @compareprice money OUTPUT

    , @listprice money OUT

    AS

    SELECT p.name AS Product, p.ListPrice AS 'List Price'

    FROM Production.Product p

    JOIN Production.ProductSubcategory s

    ON p.ProductSubcategoryID = s.ProductSubcategoryID

    WHERE s.name LIKE @product AND p.ListPrice < @maxprice;

    -- Populate the output variable @listprice.

    SET @listprice = (SELECT MAX(p.ListPrice)

    FROM Production.Product p

    JOIN Production.ProductSubcategory s

    ON p.ProductSubcategoryID = s.ProductSubcategoryID

    WHERE s.name LIKE @product AND p.ListPrice < @maxprice);

    -- Populate the output variable @compareprice.

    SET @compareprice = @maxprice;

    GO

    DECLARE @compareprice money, @cost money

    EXECUTE Production.usp_GetList '%Bikes%', 700,

    @compareprice OUT,

    @cost OUTPUT

    IF @cost <= @compareprice

    BEGIN

    PRINT 'These products can be purchased for less than

    $'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'

    END

    ELSE

    PRINT 'The prices for all products in this category exceed

    $'+ RTRIM(CAST(@compareprice AS varchar(20)))+'.'

    Thanks
    Parthi