29 lines
539 B
SQL
29 lines
539 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`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 ;
|