Home > OS >  How can make DECLARE take a value from stored procedure
How can make DECLARE take a value from stored procedure

Time:10-31

enter image description here

How can I make DECLARE @T take this value from the stored procedure?

This is my stored procedure:

ALTER PROCEDURE [dbo].[sp_GetTotlePrice]
    (@Users_Id bigint)
AS
BEGIN
    DECLARE @R TABLE
               (
                   Price bigint,
                   Quantity bigint
               )

    INSERT INTO @R
        SELECT TOP 1000000 
            M.Price, B.Quantity 
        FROM
            Basket B  
        INNER JOIN 
            Medicaments M ON M.Medicament_Id = B.Medicament_Id 
        WHERE 
            @Users_Id = B.Users_Id
        
    SELECT SUM(Price * Quantity) FROM @R
END

CodePudding user response:

I found my mistake firstly i nead to return a value in my stored procedure i add

DECLARE @T AS bigint
    SELECT @T = SUM(Price * Quantity) From @R AS TotlePrice
    --SELECT SUM(Price * Quantity) From @R AS TotlePrice
    RETURN @T

then

DECLARE @return_value bigint
EXEC    @return_value = [dbo].[sp_GetTotlePrice]
        10
SELECT  'Return Value' = @return_value
  • Related