I am creating a procedure where I'm supposed to look for the last date of an exam.
So I created a local variable for this because I will need this date in other things as well. However, when I do a simple SELECT of this local variable, I get the message:
Unknown column 'last_exam' in 'field list'.
Code:
DECLARE latest_exam date;
SELECT DATE(MAX(ex_date))
INTO latest_exam
FROM vets
WHERE an_id = p_animal_id
GROUP BY an_id;
SELECT latest_exam, and a bunch of other stuff. ;
In the select, do I need to include a FROM clause? I didn't think so because I figured latest_exam is within the procedure.
you're not assigning the result of your select in the variable.
Do this
select latest_exam = date(max(ex_date))..