I have been trying to create this stored procedure in phpMyAdmin (MySQL) and it's giving me an error, which I have stated below. I have two variables, that is advance and paid. it's to get values and subtract the loan the employee left to pay from what he has already paid for, to return what is left to pay. I have tried everything, but I can't find the error. I need help, please.
CREATE PROCEDURE getadvancebalance( IN e int, d date)
BEGIN
DECLARE advance float(50);
DECLARE paid float(50);
SELECT SUM(Amount) INTO advance
FROM vw_employee_advances
WHERE (entity_id = @e) AND (start_date <= @d) AND (approve_status = 'Approved')
IF (advance is null) THEN SET advance := 0; END IF;
SELECT SUM(Amount) INTO paid
FROM vw_advance_deductions
WHERE (entity_id = @e) AND (start_date <= @d);
IF (paid is null) THEN SET paid := 0; END IF;
advance := advance - paid;
RETURN advance;
END
This is the error, i am getting: MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4