DELIMITER //
CREATE PROCEDURE test()
BEGIN
DECLARE terms_id_var INT;
SELECT terms_id INTO terms_id_var
FROM invoices WHERE invoice_id = 4;
CASE terms_id_var
WHEN 1 THEN
SELECT 'Net due 10 days' AS Terms;
WHEN 2 THEN
SELECT 'Net due 20 days' AS Terms;
WHEN 3 THEN
SELECT 'Net due 30 days' AS Terms;
ELSE
SELECT 'Net due more than 30 days' AS Terms;
END CASE;
END//
Once again, it shows how a CASE works but the procedure is not practical
Really, I would not want to limit this to 1 invoice, I would want this to be executed in a loop for a group of invoices
What values am I expecting invoices.terms_id to contain?