salix/db/routines/vn/procedures/sale_setProblem.sql

36 lines
829 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
vProblemCode VARCHAR(25)
)
BEGIN
/**
* Update column sale.problem with a problem code
2024-07-12 06:15:09 +00:00
*
* @param vProblemCode Code to set or unset
* @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded)
*/
2024-07-12 06:15:09 +00:00
DECLARE vSaleFk INT;
DECLARE vHasProblem INT;
DECLARE vDone BOOL;
DECLARE vSaleList CURSOR FOR SELECT saleFk, hasProblem FROM tmp.sale;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
2024-07-12 06:15:09 +00:00
OPEN vSaleList;
l: LOOP
SET vDone = FALSE;
FETCH vSaleList INTO vSaleFk, vHasProblem;
2024-07-12 06:15:09 +00:00
IF vDone THEN
LEAVE l;
END IF;
UPDATE sale
SET problem = CONCAT(
IF(vHasProblem,
CONCAT(problem, ',', vProblemCode),
REPLACE(problem, vProblemCode , '')))
WHERE id = vSaleFk;
END LOOP;
CLOSE vSaleList;
END$$
DELIMITER ;