DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setProblemFreeze`( vClientFk INT ) BEGIN /** * Update the problem of tickets whose client is frozen or unfrozen * * @param vClientFk Id Cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY SELECT t.id ticketFk, FALSE hasProblem, ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vClientFk IS NULL OR t.clientFk = vClientFk); UPDATE tmp.ticket t JOIN ticket ti ON ti.id = t.ticketFk JOIN client c ON c.id = ti.clientFk SET t.hasProblem = TRUE WHERE c.isFreezed; CALL ticket_setProblem('isFreezed'); DROP TEMPORARY TABLE tmp.ticket; END$$ DELIMITER ;