2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
|
|
|
|
BEGIN
|
|
|
|
|
2024-03-06 13:11:07 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
|
|
|
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
|
|
|
(PRIMARY KEY (clientFk))
|
2024-01-15 11:31:03 +00:00
|
|
|
ENGINE = MEMORY
|
2024-03-06 13:11:07 +00:00
|
|
|
SELECT id clientFk, null grade FROM client;
|
2024-03-06 11:02:34 +00:00
|
|
|
|
|
|
|
CALL client_getDebt (maxRiskDate);
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT
|
2024-03-06 13:11:07 +00:00
|
|
|
c.RazonSocial,
|
|
|
|
c.Id_Cliente,
|
|
|
|
c.Credito,
|
|
|
|
CAST(r.risk as DECIMAL (10,2)) risk,
|
|
|
|
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
|
|
|
|
c.Id_Pais
|
|
|
|
FROM
|
|
|
|
vn2008.Clientes c
|
|
|
|
JOIN tmp.risk r ON r.clientFk = c.Id_Cliente
|
|
|
|
JOIN tmp.clientGetDebt ci ON c.Id_Cliente = ci.clientFk
|
|
|
|
GROUP BY c.Id_cliente;
|
2024-03-06 11:02:34 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
2024-03-06 13:11:07 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|