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

33 lines
795 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRisk`(
vSelf INT
)
BEGIN
/**
* Update the risk problem for a specific ticket
*
* @param vSelf Id ticket
*/
DECLARE vHasRisk BOOL;
DECLARE vHasHighRisk BOOL;
SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10))
INTO vHasRisk, vHasHighRisk
FROM client c
JOIN ticket t ON t.clientFk = c.id
JOIN clientConfig cc
WHERE t.id = vSelf;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
SELECT vSelf ticketFk, vHasRisk hasProblem;
CALL ticket_setProblem('hasRisk');
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
SELECT vSelf ticketFk, vHasHighRisk hasProblem;
CALL ticket_setProblem('hasHighRisk');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;