How can make DECLARE take a value from stored procedure.

Makki 21 Reputation points
2022-10-29T04:38:00.02+00:00

255238-screenshot-11.png

How can i make DECLARE @T take this value from stored procedure

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  
Azure SQL Database
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
986 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
Developer technologies Transact-SQL
SQL Server Other
{count} votes

1 answer

Sort by: Most helpful
  1. Makki 21 Reputation points
    2022-10-29T05:36:54.377+00:00

    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  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.