DELIMITER $$ CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`parking_algemesi`(vFromRow INT, vToRow INT, vSectorFk INT, vLetter VARCHAR(1), vPickingOrder INT, vTrolleysByLine INT) BEGIN DECLARE vRow INT; DECLARE vCode VARCHAR(8); DECLARE i INT; IF vToRow < vFromRow THEN SET vRow = vFromRow; WHILE vRow >= vToRow DO SET i = 1; WHILE i <= vTrolleysByLine DO SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10)) ON DUPLICATE KEY UPDATE `code` = vCode; SET i = i + 1; END WHILE; SET vRow = vRow - 1; END WHILE; ELSE SET vRow = vFromRow; WHILE vRow <= vToRow DO SET i = 1; WHILE i <= vTrolleysByLine DO SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10) ) ON DUPLICATE KEY UPDATE `code` = vCode; SET i = i + 1; END WHILE; SET vRow = vRow + 1; END WHILE; END IF; END$$ DELIMITER ;