salix/db/routines/vn/procedures/workerCalculateBoss.sql

29 lines
533 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`workerCalculateBoss`(vWorker INT)
BEGIN
/**
* Actualiza la tabla workerBosses
* vWorker: id del trabajador
*
*/
DECLARE vBoss INT;
DECLARE vWorkerCompare INT DEFAULT vWorker;
l: LOOP
SELECT bossFk INTO vBoss
FROM vn.worker
WHERE id=vWorkerCompare;
IF vBoss=0 OR vWorkerCompare=vBoss THEN
LEAVE l;
END IF;
REPLACE INTO vn.workerBosses(workerFk,bossFk)
VALUES(vWorker,vBoss);
SET vWorkerCompare = vBoss;
END LOOP;
END$$
DELIMITER ;