lot lot - 2 years ago 60
SQL Question

Is there a way to automatically update a value based on the date?

I have a table with two columns,

(datetime) and

The user can give in this date at any given time. Is there a way to automatically update
is less than today's date? A script or something? Thanks!

Answer Source

I would suggest that you use a view:

create view v_table as
    select t.*,
           (startdate <= curdate() then 1 else 0 end) as has_started
    from table t;

If you query the view, the has_started column will be updated when accessed. The value doesn't need to be stored in the database.

(Note: if there is a time component, you can use now() instead of curdate().)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download