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

21 lines
410 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`currentRate`(vCurrencyFk INT, vDated DATE)
RETURNS decimal(10,4)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE curRate DECIMAL(10,4);
SELECT value INTO curRate
FROM referenceRate
WHERE dated <= vDated
AND currencyFk = vCurrencyFk
ORDER BY dated DESC
LIMIT 1;
RETURN curRate;
END$$
DELIMITER ;