Följande knep kan hjälpa:
DELIMITER //
CREATE FUNCTION `return_integer`(`number` INT UNSIGNED)
RETURNS INT UNSIGNED DETERMINISTIC
BEGIN
RETURN `number`;
END//
DELIMITER ;
SELECT
CASE `L`.`Code`
WHEN 'ABCD' THEN `return_integer`(0)
ELSE `L`.`ID`
END AS XLID
FROM `table_name` `L`;