SQL 9. Variables

– – Local variables
DELIMITER $$
CREATE PROCEDURE Get_Risk_Factor()
BEGIN

Risk_Factor = Invoices_Total/Invoices_Count * 5

DECLARE Risk_Factor DECIMAL (9, 2) DEFAULT 0;
DECLARE Invoices_Total DECIMAL (9, 2);
DECLARE Invoices_Count INT;

SELECT
COUNT(*),
SUM(Invoice_Total)
INTO Invoices_Count, Invoices_Total
FROM Invoices;

SET Risk_Factor = (Invoices_Total / Invoices_Count) * 5;
SELECT Risk_Factor;
END$$
DELIMITER ;

call part2_invoicing.Get_Risk_Factor();
Returns 777.75 !