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

39 lines
950 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblemAll`()
BEGIN
/**
* Update the risk problem for all tickets
*
*/
CREATE OR REPLACE TEMPORARY TABLE tRisk
(KEY (ticketFk))
ENGINE = MEMORY
SELECT t.id ticketFk,
t.risk > (c.credit + 10) hasRisk,
((t.risk - cc.riskTolerance) > (c.credit + 10)) hasHighRisk
FROM client c
JOIN ticket t ON t.clientFk = c.id
JOIN clientConfig cc
WHERE t.shipped >= util.midnight();
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(KEY (ticketFk))
ENGINE = MEMORY
SELECT ticketFk, hasRisk hasProblem
FROM tRisk;
CALL ticket_setProblem('hasRisk');
DROP TEMPORARY TABLE tmp.ticket;
CREATE TEMPORARY TABLE tmp.ticket
(KEY (ticketFk))
ENGINE = MEMORY
SELECT ticketFk, hasHighRisk hasProblem
FROM tRisk;
CALL ticket_setProblem('hasHighRisk');
DROP TEMPORARY TABLE tmp.ticket;
DROP TEMPORARY TABLE tRisk;
END$$
DELIMITER ;