so I'm try to create auto increment by using trigger with case the case works when the parameter insert but the value is not auto increment and stay "001" here is the code
DELIMITER $$
USE `onlinestore`$$
DROP TRIGGER /*!50032 IF EXISTS */ `trigger_sensors`$$
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `trigger_sensors` BEFORE INSERT ON `sensors`
FOR EACH ROW
BEGIN
IF (NEW.label IS NULL) THEN
-- Find max existed label for specified sensor type
SELECT
MAX(label) INTO @max_label
FROM
sensors
WHERE
TYPE = NEW.name;
IF (@max_label IS NULL) THEN
SET @label =
CASE NEW.name
WHEN 'VIP' THEN 'VIP'
WHEN 'REGULER' THEN 'R'
WHEN 'MROOM' THEN 'MR'
ELSE 'UNKNOWN'
END;
-- Set first sensor label
SET NEW.label = CONCAT(@label, '001');
ELSE
-- Set next sensor label
SET NEW.label = CONCAT(SUBSTR(@max_label, 1, 2), LPAD(SUBSTR(@max_label, 3) + 1, 4, '0'));
END IF;
END IF;
END;
$$
DELIMITER ;
i cannot find where did I does wrong.... can someone help me?
