this might help:create table t_dates(id int not null,archive datetime,expiry datetime,caseif char(1))insert into t_dates (id, archive, expiry, caseif) values (1, getdate(), getdate()+3, 0) insert into t_dates (id, archive, expiry, caseif) values (2, getdate(), getdate()-5, 0)insert into t_dates (id, archive, expiry, caseif) values (3, getdate(), getdate()+12, 0)insert into t_dates (id, archive, expiry, caseif) values (4, getdate(), getdate()+3, 0)update t_datesset caseif = 1where archive >= expiry