DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`Conteo_afterInsert` AFTER INSERT ON `Conteo` FOR EACH ROW BEGIN DECLARE intTravel INTEGER; SELECT t.id INTO intTravel FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE landing = util.VN_CURDATE() AND c.Id_Article = NEW.Id_Article AND warehouse_id = NEW.warehouse_id AND received <> TRUE LIMIT 1; IF (intTravel) then UPDATE travel SET received = TRUE WHERE id = intTravel; END IF; END$$ DELIMITER ;