Last answered:

09 Feb 2022

Posted on:

02 Feb 2022

0

Just curious why my response is a null...

Just wondering why my query didn't work (Null).  All that looks to be different to me is that I did not write two separate select into queries:

use employees;
DROP FUNCTION IF EXISTS emp_info;
DELIMITER $$
CREATE FUNCTION emp_info(p_first_name VARCHAR (255), p_last_name VARCHAR (255)) RETURNS DECIMAL(10,2)

DETERMINISTIC NO SQL READS SQL DATA
BEGIN
DECLARE
v_max_from_date DATE;
DECLARE
v_salary DECIMAL(10,2);
SELECT MAX(from_date), salary
INTO v_max_from_date, v_salary FROM
salaries s
JOIN
employees e on e.emp_no = s.emp_no
                    where p_first_name = e.first_name and p_last_name = e.last_name AND s.from_date = v_max_from_date;
RETURN v_salary;
END$$
DELIMITER ;

SELECT emp_info('Aruna', 'Journel');

Thanks!

1 answers ( 0 marked as helpful)
Instructor
Posted on:

09 Feb 2022

0

Hi Crystal!

Thanks for reaching out.

Yes, this is the reason. You should use two SELECT statements.

Hope this helps.
Best,
Tsvetelin

Submit an answer