1

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

moses toh
  • 12,344
  • 71
  • 243
  • 443

2 Answers2

3

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 ;
meda
  • 45,103
  • 14
  • 92
  • 122
0

You can do your above operations( 2 updates) in single update itself

use the below script

CREATE EVENT update_status
ON SCHEDULE EVERY 2 MINUTE
DO
UPDATE customer_group
SET is_status = (select case when CURRENT_TIMESTAMP BETWEEN start_date AND end_date then 0 else 1 end from customer_group limit 1);

for more details use this http://www.mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event/

Andrews B Anthony
  • 1,381
  • 9
  • 27