1

I have a mySQL database where I need to check the most recent day in a table and call a procedure if a day has passed. So I tried this code:

DECLARE mDay DATE;

SELECT `date`  INTO mDay
FROM TimeTable ORDER BY `date` DESC
LIMIT 1;

IF(mDay = NULL OR mDay != DATE(CURRENT_TIMESTAMP)) THEN
    CALL UpdateTimeTable()
END IF;

(In my current test case the TimeTable is empty.)

But the procedure never gets called, so I tried changing the condition to: mDay = NULL OR mDay != NULL, and it still didn't get called. Then I tried mDay = DATE(CURRENT_TIMESTAMP) OR mDay != DATE(CURRENT_TIMESTAMP) and it still didn't get called.

Finally I changed it to simply true and then it calls the procedure.

What's going wrong here?

Patrick Jeeves
  • 371
  • 2
  • 16
  • 2
    Should that test of `= NULL` be `IS NULL`? As seen in this Question, [How to check if a variable is NULL, then set it with a MySQL stored procedure?](http://stackoverflow.com/questions/18499747/how-to-check-if-a-variable-is-null-then-set-it-with-a-mysql-stored-procedure). I'm a [Postgres](http://www.postgresql.org/) guy, not a MySQL guy, so I don't know for sure. – Basil Bourque Jul 03 '15 at 19:48

1 Answers1

1

It was because mySQL uses IS NULL and IS NOT NULL for comparison against NULL, and = for everything else.

Patrick Jeeves
  • 371
  • 2
  • 16