Karthik K

Karthik K

  • 1.3k
  • 479
  • 49.5k

How to Pass DB Name as Parameter in mysql server ?.

Mar 17 2020 3:38 AM
Hi All ,
 
    I have situation to pass database Name as Parameter in mysql storedprocedure . But i have issue on this i share my procedure .If anyone knows suggest me with example.
 
 
 
DELIMITER //
CREATE PROCEDURE GetRecord
(
IN R_BranchName varchar(100),
IN R_Year Date ,
IN R_Month Date ,
IN R_CurrDate date
)
BEGIN
SET @Db=R_BranchName;
select sum(H.TotalSales) As TotalSales ,H.Month , sum(H.total) as Total from
(
select (sum(tp.PaymentAmount)) as Totalsales,Monthname(tp.BusinessDate) as Month ,0 as Total from '@Db'.transpayment tp left join '@Db'.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
union All
select 0.00 as Totalsales,'' as Month ,sum(tp.PaymentAmount) as total from '@Db'.transpayment tp left join '@Db'.trans t on tp.TransID=t.TransID where tp.BusinessDate between R_CurrDate and R_CurrDate and t.TransStatus in (2,3,4)
) as H ;
END
//DELIMITER ;
 
 When pass following values the above stored Procedure Need to Run. (Above procedure Not Run due  ' @db' this value 
 
CALL GetRecord('Chive1',Year(Curdate()), Month(Curdate()),Curdate() ); 
 
 
 
Thanks in Advance 
 
 
Karthik K 

Answers (2)