moses toh moses toh - 5 months ago 29
SQL Question

How to run two update query in mysql event scheduler?

Mysql event scheduler is like this :

CREATE EVENT update_status
ON SCHEDULE EVERY 2 MINUTE
DO
BEGIN
UPDATE customer_group
SET is_status = 0
WHERE CURRENT_TIMESTAMP BETWEEN start_date AND end_date;
UPDATE customer_group
SET is_status = 1
WHERE CURRENT_TIMESTAMP NOT BETWEEN start_date AND end_date;
END


When I run the script, there is exist error like this :

Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7


Any solution to solve my problem?

Thank you very much

Answer

I cannot spot the error , try this :

DELIMITER $$
CREATE EVENT update_status
ON SCHEDULE
    EVERY 2 MINUTE
DO
BEGIN
    UPDATE
       customer_group      
    SET
       is_status = 0      
    WHERE
       CURRENT_TIMESTAMP BETWEEN start_date AND end_date;      
    UPDATE
        customer_group       
    SET
       is_status = 1      
    WHERE
        CURRENT_TIMESTAMP NOT BETWEEN start_date AND end_date;
END $$
DELIMITER ;
Comments