2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`workerCalculateBoss`(vWorker INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|