DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLackByComponent`( vComponentFk INT ) BEGIN /** * Update the issues for sales lines that have or no longer have problems with components, verify * whether all mandatory components are present or not resulting from changes in the table vn.component * * @param vComponentFk Id component */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk)) ENGINE = MEMORY SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE t.shipped >= util.midnight() AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk); CALL sale_setProblem('hasComponentLack'); DROP TEMPORARY TABLE tmp.sale; END$$ DELIMITER ;