First page Back Continue Last page Image

A Stored Procedure IF Statement Example

DELIMITER //

 

CREATE PROCEDURE test()

BEGIN

DECLARE first_invoice_due_date DATE;

 

SELECT MIN(invoice_due_date)

INTO first_invoice_due_date

FROM invoices

WHERE invoice_total - payment_total - credit_total > 0;

 

IF first_invoice_due_date < NOW() THEN

SELECT 'Outstanding invoices are overdue!';

ELSEIF first_invoice_due_date = NOW() THEN

SELECT 'Outstanding invoices are due today!';

ELSE

SELECT 'No invoices are overdue.';

END IF;

END//

While this does show how a IF statement can be used, the procedure itself does not make much sense

Why only look at 1 invoice