Here is a simple function that can help coping with wrong
database design, when you have a mix of NULLs and blank fields
meaning the same, no value, which they shouldn't.
- DELIMITER $$
- DROP FUNCTION IF EXISTS `test`.`is_initial` $$
- CREATE FUNCTION `test`.`is_initial` (f varchar(255)) RETURNS BOOL
- BEGIN
- SET @is_initial = false;
- CASE f
- WHEN NULL THEN SET @is_initial = TRUE;
- WHEN '' THEN SET @is_initial = TRUE;
- ELSE SET @is_initial = FALSE;
- END CASE;
- RETURN @is_initial;
- END $$
- DELIMITER ;