Hy, I have the following function on my mysql schema, this function should work like this:
if (especie=mEspecie && variedad=mVariedad) then
then return precio; else
return 0;
end if;
but somehow it's not working, anybody can help me here?.
this is my function, I've updated since @vipin answer:
CREATE DEFINER=`root`@`localhost` FUNCTION `BUSCA_PRECIO_MATRIZ`(mEspecie int, mVariedad int) RETURNS int(11)
READS SQL DATA
DETERMINISTIC
BEGIN
declare precio, especie,variedad integer;
declare cur1 cursor for
select ifnull(valor,0),idconf_especie,idconf_variedad from cc_matriz_precios_facturacion_recibidor where idconf_especie=mEspecie and idconf_variedad=mVariedad;
open cur1;
loop_cur : loop
fetch cur1 into precio,especie,variedad;
if(especie = mEspecie) then
if (variedad = mVariedad) then
return variedad;
LEAVE loop_cur;
else
return variedad;
leave loop_cur;
end if;
end if;
end loop;
return 0;
close cur1;
return 0;
END