DELIMITER $$
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 ;
