salix/db/routines/vn/functions/getSpecialPrice.sql

24 lines
670 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`getSpecialPrice`(vItemFk int(11),vClientFk int(11))
RETURNS decimal(10,2)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE price DECIMAL(10,2);
SELECT rate3 INTO price
FROM vn.priceFixed
WHERE itemFk = vItemFk
AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1;
SELECT `value` INTO price
FROM vn.specialPrice
2024-03-26 11:07:23 +00:00
WHERE itemFk = vItemFk
AND (clientFk = vClientFk OR clientFk IS NULL)
AND started <= util.VN_CURDATE()
AND (ended >= util.VN_CURDATE() OR ended IS NULL)
ORDER BY id DESC LIMIT 1;
RETURN price;
END$$
DELIMITER ;