I am using CASE statement in a function in mysql like this:
BEGIN
declare Rslt1 decimal(10,2);declare Rslt2 int;declare Rslt3 int;
declare Rslt decimal(10,2);declare Tot decimal(10,2);
set Tot = UnitPrice * OrderQty;
if Calctype = 0 then
set Rslt1 = Tot;
elseif CalcType=1 then -- Buy X Pay Y
set Rslt2 = floor((OrderQty/X));
set Rslt3 = (Orderqty - (RSlt2 * X));
set Rslt1 = CASE
WHEN Rslt2 =0 THEN Tot
WHEN Rslt2>=1 THEN amntpercent(((Rslt2 * UnitPrice * X),ByAmnt, Dscnt) + (Rslt3 * UnitPrice))
End;
elseif CalcType = 2 then -- for X Pay Y ( Discount by Amnount or Percentage)
set RSlt1= amntpercent(Tot,ByAmny,Dscnt);
end if;
RETURN (Rslt1);
but I am getting this error every time. Any help please
seems you have wrong () in a WHEN condition
try
WHEN Rslt2>=1 THEN amntpercent((Rslt2 * UnitPrice * X),ByAmnt, Dscnt) + (Rslt3 * UnitPrice)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.