DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBookingRange`() BEGIN /* Reasentar facturas */ DECLARE vInvoice INT; DECLARE vContador INT DEFAULT 0; DECLARE done BOOL DEFAULT FALSE; DECLARE rs CURSOR FOR SELECT io.id FROM invoiceOut io WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224 AND serial = 'T'; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN rs; FETCH rs INTO vInvoice; WHILE NOT done DO CALL invoiceOutBooking(vInvoice); FETCH rs INTO vInvoice ; SET vContador = vContador + 1; IF vContador MOD 50 = 0 THEN SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS; END IF; END WHILE; CLOSE rs; SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS; END$$ DELIMITER ;