salix/db/routines/bs/events/clientDied_recalc.sql

29 lines
662 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `bs`.`clientDied_recalc`
ON SCHEDULE EVERY 1 DAY
STARTS '2023-06-01 03:00:00.000'
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
DECLARE vDone INT DEFAULT FALSE;
DECLARE vCountryFk INT;
DECLARE vDays INT;
DECLARE cur CURSOR FOR
SELECT countryFk, days
FROM clientDiedPeriod;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN cur;
read_loop: LOOP
SET vDone = FALSE;
FETCH cur INTO vCountryFk, vDays;
IF vDone THEN
LEAVE read_loop;
END IF;
CALL clientDied_recalc(vDays, (SELECT code FROM vn.country WHERE id = vCountryFk));
END LOOP;
CLOSE cur;
END$$
DELIMITER ;