I have a stored procedure which takes in a datetime field along with some other fields. The datetime field is allowed to be empty or NULL but when it is passed in it gets passed as an empty string, ''. This causes a problem as my sql admin says that the datetime field is not proper format. How do I convert the '' to a NULL value. I have tried if statements and they do not work. My code is below for the stored proc.
DELIMITER $$
DROP PROCEDURE IF EXISTS `dev_db`.`insert_emp` $$
CREATE DEFINER=`development`@`%` PROCEDURE `insert_emp` (
IN _fname_ VARCHAR(50),
IN _lname_ VARCHAR(50),
IN _dob_ DATETIME
)
BEGIN
//if an empty string is passed set the value to NULL so it can be inserted
IF(_dob_ = '' ) THEN
SET _dob_ = NULL;
END IF;
INSERT INTO emp(f_name, l_name, dob) VALUES(_fname_, _lname_, _dob_);
//return the id of the inserted employee
SELECT MAX(emp_id) INTO return_id FROM emp;
END $$
DELIMITER;