MySQL更新 - 如果日期尚未过去,则设置字段

I have a question regarding case/if statements in MySQL in regards to updating a field based on the possibility of a date in a field. I have two fields. One that contains a date ("LastDayToNotify") and one that contains a plaintext message ("NotifyMessage")

The date field can contain one of three values - An empty field, a Null, or a Date.

My question is - Is it possible, and if so how, to in MySQL to have a query that sets one field's value (NotifyMessage) based on if the date (LastDayToNotify) has passed? An example would be :

If the date has not passed (the date is today or before), update the NotifyMessage field to say "Generic Message"

but if the date field is empty, null, or it is passed it does nothing.

I've tested a couple modifactions of answers in this thread, but have been unable to successfully account for all 3 possible date scenarios. Here

I know this is probably a rookie question, but I've never encountered this particular need yet.

Thanks!

I'm assuming you're using sane field types (date or datetime)...

UPDATE table
SET
    NotifyMessage = 'Generic Message'
WHERE
    LastDayToNotify IS NOT NULL
    AND LastDayToNotify >= CURDATE();

If you're not already storing the dates as date types, take a look at: Converting a date in MySQL from string field

In my experience you cant set a value with a CASE statement but you can list something. This however will appear as a separate column.

E.G

    CASE WHEN date < SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
    THEN "Generic Message"
    ELSE 0 
    END AS 'Before Today'

You would have to then create more case statements to cover other scenarios such as NULL

You can use this simple query:

UPDATE yourTable SET NotifyMessage = 'Generic Message'
WHERE LastDayToNotify <= CURDATE();