Mysql函数返回相同的值

时间:2013-03-21 10:57:41

标签: mysql function

我需要mysql函数,但每次都给出相同的值 这个mysql函数每次都给我相同的值,即S_Start_ToBeStarted(第1个If的值)

-- colorA
DELIMITER $$
DROP FUNCTION IF EXISTS `colorA`$$
CREATE FUNCTION `colorA`( 
    Appf VARCHAR(3), 
    Start_Datef DATETIME, 
    PDCf DATETIME
    ) RETURNS INT
    DETERMINISTIC
BEGIN
DECLARE finalcolor INT DEFAULT 0;
IF Appf = 'Yes' & IFNULL(Start_Datef, 'NULL' = 'NULL' & sysdate() <= PDCf
    THEN SET finalcolor = (SELECT `PP_Colors`.`S_Start_ToBeStarted` FROM `SCR_Sap`.`PP_Colors` LIMIT 1);

ELSE IF Appf = 'Yes' & IFNULL(Start_Datef, 'NULL') = 'NULL' & sysdate() > PDCf
    THEN SET finalcolor = (SELECT `PP_Colors`.`S_Start_Error` FROM `SCR_Sap`.`PP_Colors` LIMIT 1);

ELSE IF Appf = 'Yes' & IFNULL(Start_Datef, 'NULL') != 'NULL' & sysdate() <= PDCf
    THEN SET finalcolor = (SELECT `PP_Colors`.`S_Start_Ok` FROM `SCR_Sap`.`PP_Colors` LIMIT 1);

ELSE IF Appf = 'Yes' & IFNULL(Start_Datef, 'NULL') != 'NULL' & sysdate() > PDCf
    THEN SET finalcolor = (SELECT `PP_Colors`.`S_Start_LateStarted` FROM `SCR_Sap`.`PP_Colors` LIMIT 1);

ELSE SET finalcolor = (SELECT `PP_Colors`.`S_NotApplicable` FROM `SCR_Sap`.`PP_Colors` LIMIT 1);

END IF;
END IF;
END IF;
END IF;
    RETURN finalcolor;
    END$$
DELIMITER ;

1 个答案:

答案 0 :(得分:0)

Null与=!=运算符不兼容,foobar=NULL的结果为NULL(未知)不为true或false。请改用IS NULLIS NOT NULL