Karthik K

Karthik K

  • 1.2k
  • 429
  • 45.1k

Get Stored Procedure Result Set values in Mysql server ?

Mar 18 2020 10:27 PM
Hi All , 
 
I want to read Result set values of this Procedure in Mysqlserver Database . 
      
CALL GetRecord('chive5',@R_TotalSales ,@R_MonthlySale);  
 
 Total sale      Total
 21132.6000  386.6000
    
The above procedure Return like this , I want read and update this value in another table. I have get TotalSale as well as Total.  Can Anyone suggest with example stored Procedure. 
  
my Procedure : 
  1. DELIMITER $$  
  2. CREATE DEFINER=`root`@`%` PROCEDURE `chivehq`.`GetRecord`(  
  3. IN R_BranchName varchar(100), OUT R_TotalSales decimal(15,2),OUT R_MonthlySale decimal(15,2)  
  4. )  
  5. BEGIN  
  6. DECLARE SQLStmt TEXT;  
  7. declare R_Year date;  
  8. declare R_Month date;  
  9. declare R_CurrDate date;  
  10. SET @Branch=R_BranchName;  
  11. set @R_Year=Year(Curdate());  
  12. set @R_Month=Month(Curdate());  
  13. set @R_CurrDate=Curdate();  
  14. SET @R_TotalSales=0;  
  15. SET @R_MonthlySale=0;  
  16. SET @SQLStmt=CONCAT  
  17. (  
  18. 'select sum(H.TotalSales) As TotalSales ,H.Month , sum(H.total) as Total from  
  19. (  
  20. select (sum(tp.PaymentAmount)) as Totalsales,Monthname(tp.BusinessDate) as Month ,0 as Total from ',R_BranchName,'.transpayment tp left join ',R_BranchName,'.trans t on tp.TransID=t.TransID where t.TransStatus in (2,3,4) and year(tp.BusinessDate)=',@R_Year,' and MONTH(tp.BusinessDate)=',@R_Month,'  
  21. union All  
  22. select 0.00 as Totalsales, null as Month ,sum(tp.PaymentAmount) as total from ',R_BranchName,'.transpayment tp left join ',R_BranchName,'.trans t on tp.TransID=t.TransID where tp.BusinessDate between ','@R_CurrDate',' and ','@R_CurrDate',' and t.TransStatus in (2,3,4)  
  23. as H  
  24. ');  
  25. PREPARE Stmt FROM @SQLStmt;  
  26. EXECUTE Stmt;  
  27. DEALLOCATE PREPARE Stmt;  
  28. END $$  
  29. DELIMITER ;  
Thanks in Advance ,
 
Karthik K

Answers (1)