mardi 31 janvier 2017

MySQL event with IF-ELSE clause is not working

I have this event in my DB and it was working great without the IF-ELSE clause. It was like this before:

DELIMITER $$
CREATE EVENT update_count_days
ON SCHEDULE EVERY '1' minute
STARTS '2017-01-01 00:00:00'
DO 
BEGIN
     SET SQL_SAFE_UPDATES = 0;
    UPDATE bots SET days_from_start = datediff(current_date(),start_date);
END$$    
DELIMITER ;

However, When I've dropped the event and add the IF-ELSE clause, the event stopped working:

DELIMITER $$
CREATE EVENT update_count_days
ON SCHEDULE EVERY '1' minute
STARTS '2017-01-01 00:00:00'
DO 
BEGIN

    IF (end_date IS NULL) THEN
     SET SQL_SAFE_UPDATES = 0;
    UPDATE bots SET days_from_start = datediff(current_date(),start_date);
    else
     SET SQL_SAFE_UPDATES = 0;
    UPDATE bots SET days_from_start = datediff(end_date,start_date);
    END IF;
END$$    
DELIMITER ;

Can you please help me figure out what's the problem? Thank you!

Aucun commentaire:

Enregistrer un commentaire