Event schedule start with case clause : Schedule « Event « SQL / MySQL






Event schedule start with case clause

     
mysql>
mysql> CREATE TABLE EVENTS_INVOKED
    ->       (EVENT_NAME      VARCHAR(20) NOT NULL,
    ->        EVENT_STARTED   TIMESTAMP NOT NULL);
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> CREATE EVENT FIVESUNDAYS
    ->    ON SCHEDULE EVERY 1 WEEK
    ->       STARTS CASE DAYNAME(NOW())
    ->          WHEN 'Sunday'    THEN NOW()
    ->          WHEN 'Monday'    THEN NOW() + INTERVAL 6 DAY
    ->          WHEN 'Tuesday'   THEN NOW() + INTERVAL 5 DAY
    ->          WHEN 'Wednesday' THEN NOW() + INTERVAL 4 DAY
    ->          WHEN 'Thursday'  THEN NOW() + INTERVAL 3 DAY
    ->          WHEN 'Friday'    THEN NOW() + INTERVAL 2 DAY
    ->          WHEN 'Saturday'  THEN NOW() + INTERVAL 1 DAY
    ->       END
    ->       ENDS CASE DAYNAME(NOW())
    ->          WHEN 'Sunday'    THEN NOW()
    ->          WHEN 'Monday'    THEN NOW() + INTERVAL 6 DAY
    ->          WHEN 'Tuesday'   THEN NOW() + INTERVAL 5 DAY
    ->          WHEN 'Wednesday' THEN NOW() + INTERVAL 4 DAY
    ->          WHEN 'Thursday'  THEN NOW() + INTERVAL 3 DAY
    ->          WHEN 'Friday'    THEN NOW() + INTERVAL 2 DAY
    ->          WHEN 'Saturday'  THEN NOW() + INTERVAL 1 DAY
    ->       END + INTERVAL 4 WEEK
    ->    DO INSERT INTO EVENTS_INVOKED
    ->       VALUES ('FIVESUNDAYS',NOW());
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop table EVENTS_INVOKED;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

   
    
    
    
    
  








Related examples in the same category

1.Event schedule every week
2.ON SCHEDULE AT NOW()
3.ON COMPLETION PRESERVE
4.ON SCHEDULE EVERY 1 MONTH
5.ON SCHEDULE EVERY 3 MONTH