DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN /* * @deprecated:utilizar ticket_setState */ DECLARE vAlertLevel INT; SELECT s.alertLevel INTO vAlertLevel FROM vn.state s JOIN vn.ticketState ts ON ts.stateFk = s.id WHERE ts.ticketFk = vTicketFk; IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT id, vTicketFk, account.myUser_getId() FROM vn.state WHERE `code` = vStateCode collate utf8_unicode_ci; END IF; END$$ DELIMITER ;