62,067
社区成员
发帖
与我相关
我的任务
分享
declare @t table(id int,time datetime)
insert @t select 1,'2008-01-01 12:30:10'
union all select 2,'2008-02-01 08:30:10'
union all select 3,'2008-03-01 20:30:10'
union all select 4,'2008-04-01 12:30:10'
union all select 4,'2008-06-01 01:30:10'
union all select 4,'2008-07-01 12:30:10'
select * from @t
where [time]>='2008-1-1' and [time]<='2008-4-1 23:59:59'
/*
(所影响的行数为 6 行)
id time
----------- ------------------------------------------------------
1 2008-01-01 12:30:10.000
2 2008-02-01 08:30:10.000
3 2008-03-01 20:30:10.000
4 2008-04-01 12:30:10.000
(所影响的行数为 4 行)
*/
select * from table where time between '2008-01-01' and DateAdd(day,1,'2008-04-01')
--注释:例如想找2008-8-8 15:08:85 159之前的记录,那将时间加多一天