salix/db/routines/vn/procedures/nextShelvingCodeMake.sql

42 lines
816 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`nextShelvingCodeMake`()
BEGIN
DECLARE newShelving VARCHAR(3);
DECLARE vCode VARCHAR(3);
SELECT MAX(code) INTO vCode
FROM vn.shelving
WHERE isPrinted = FALSE;
SET @a1 := ASCII(MID(vCode,1,1));
SET @a2 := ASCII(MID(vCode,2,1));
SET @a3 := ASCII(MID(vCode,3,1)) + 1;
IF @a3 > 90 THEN
SET @a3 = 65;
SET @a2 = @a2 + 1;
IF @a2 > 90 THEN
SET @a2 = 65;
SET @a1 = @a1 + 1;
IF @a1 > 90 THEN
SET @a1 = 65;
END IF;
END IF;
END IF;
SET newShelving = CHAR(@a1,@a2,@a3 USING utf8);
INSERT INTO vn.shelving(code) VALUES(newShelving);
END$$
DELIMITER ;