29 lines
535 B
MySQL
29 lines
535 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`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 ;
|