I am writing a function that should return a floating value.
BEGIN
DECLARE due_amount DECIMAL(9,2);
SET due_amount = (SELECT due_amount FROM (
SELECT id, MAX(date), due_amount, user_id
FROM lunch_transaction
GROUP BY user_id
HAVING user_id = user) l);
IF due_amount IS NULL THEN
SET due_amount = 0.00;
END IF;
RETURN due_amount;
END
The function only returns value 0.00
even though the value should be something else.
Running only this query :
(SELECT due_amount FROM (
SELECT id, MAX(date), due_amount, user_id
FROM lunch_transaction
GROUP BY user_id
HAVING user_id = user) l);
is giving the correct output though.
How should I set the query's output to the variable?