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

30 lines
781 B
MySQL
Raw Normal View History

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))
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);
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
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
2024-03-06 13:11:07 +00:00
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
END$$
DELIMITER ;