日期:2014-05-17 浏览次数:20545 次
select * from dbo.Tab_Article where ADate between '2009-09-14' and '2009-09-14'
declare @sdt datetime ,@edt datetime set @sdt='2009-09-14' set @edt='2009-09-14' select 精确毫秒=dateadd(ms,-1,dateadd(dd,1,@edt)),精确到秒=dateadd(ss,-1,dateadd(dd,1,@edt)) /* 精确毫秒 精确到秒 ------------------------------------------------------ ------------------------------------------------------ 2009-09-15 00:00:00.000 2009-09-14 23:59:59.000 (所影响的行数为 1 行) */ --所以只能精确到秒,修改如下 select * from dbo.Tab_Article where ADate between @sdt and dateadd(ss,-1,dateadd(dd,1,@edt)
------解决方案--------------------
if object_id('tb') is not null drop table tb create table tb(dt datetime) insert tb select '2009-10-20 12:52:52' union all select '2009-10-20 00:00:00' union all select '2009-10-20 23:59:59' union all select '2009-10-21 00:00:00' union all select '2009-10-21 12:52:52' select * from tb where dt>='2009-10-20' and dt<'2009-10-21' /* 2009-10-20 12:52:52.000 2009-10-20 00:00:00.000 2009-10-20 23:59:59.000 */ select * from tb where dt between '2009-10-20' and '2009-10-21' /* 2009-10-20 12:52:52.000 2009-10-20 00:00:00.000 2009-10-20 23:59:59.000 2009-10-21 00:00:00.000 */
------解决方案--------------------
select * from dbo.Tab_Article where ADate between @startdate and dateadd(day,1,@enddate)
------解决方案--------------------
select * from dbo.Tab_Article where ADate between '2009-09-14' and '2009-09-14'
select * from dbo.Tab_Article where ‘2009-09-14 00:00:00 ’《=ADate《=’2009-09-14:23:59:59'