日期:2014-05-16 浏览次数:20549 次
CREATE TABLE test(date1 DATETIME,date2 DATETIME,flag AS case when getdate() between date1 and date2 then 0 else 1 end )
INSERT INTO test(date1,date2) values('2013-01-01','2014-04-01')
SELECT * FROM test
INSERT INTO test(date1,date2) values('2016-01-01','2017-04-01')
SELECT * FROM test
/*
date1 date2 flag
----------------------- ----------------------- -----------
2013-01-01 00:00:00.000 2014-04-01 00:00:00.000 0
(1 row(s) affected)
(1 row(s) affected)
date1 date2 flag
----------------------- ----------------------- -----------
2013-01-01 00:00:00.000 2014-04-01 00:00:00.000 0
2016-01-01 00:00:00.000 2017-04-01 00:00:00.000 1
*/