USE `vn`; DROP function IF EXISTS `getSpecialPrice`; DELIMITER $$ USE `vn`$$ CREATE DEFINER=`root`@`%` FUNCTION `getSpecialPrice`(vItemFk int(11),vClientFk int(11)) RETURNS decimal(10,2) BEGIN DECLARE price DECIMAL(10,2); SELECT rate3 INTO price FROM vn.priceFixed WHERE itemFk = vItemFk AND CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; SELECT `value` INTO price FROM vn.specialPrice WHERE itemFk = vItemFk AND clientFk = vClientFk ; RETURN price; END$$ DELIMITER ;