DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( vProblemCode VARCHAR(25) ) BEGIN /** * Update column ticket.problem with a problem code * * @param vProblemCode Code to set or unset * @table tmp.ticket(ticketFk, hasProblem) */ UPDATE ticket t JOIN tmp.ticket tt ON tt.ticketFk = t.id SET t.problem = CONCAT( IF(tt.hasProblem, CONCAT(problem, ',', vProblemCode), REPLACE(problem, vProblemCode , ''))); END$$ DELIMITER ;