USE ap;
DROP PROCEDURE IF EXISTS test;
-- Change statement delimiter from semicolon to double front slash
DELIMITER //
CREATE PROCEDURE test()
BEGIN
DECLARE sum_balance_due_var DECIMAL(9, 2);
SELECT SUM(invoice_total - payment_total - credit_total)
INTO sum_balance_due_var
FROM invoices
WHERE vendor_id = 95;
IF sum_balance_due_var > 0 THEN
SELECT CONCAT('Balance due: $', sum_balance_due_var) AS message;
ELSE
SELECT 'Balance paid in full' AS message;
END IF;
END//
-- Change statement delimiter from double front slash to semicolon
DELIMITER ;
CALL test();
Unless Vendor 95 is a problem vendor this procedure is not practical, perhaps if I passes the Vendor ID in as a variable it would make more sense
The output of this procedure will either show a Balance Due or say Balance Paid in Full