[英]Datetime Comparing Operation
I have these record in my database : 我的数据库中有这些记录:
the date
column type in datetime
的date
的列类型中datetime
Also i have a query for fetching some records from the table : 我也有查询从表中获取一些记录:
SELECT count(*)
FROM Availibility
WHERE [date]>= @StartDate AND [date]<=@EndDate
And this is screen shot from the result : 这是结果的屏幕截图:
I expected to have Count(*) = 5 but i got 4 !!! 我期望有Count(*)= 5但我有4个!!! What's my mistake? 我怎么了
UPDATE UPDATE
Changing SELECT COUNT(*)
to SELECT *
: 将SELECT COUNT(*)
更改为SELECT *
:
And these are the latest records : 这些是最新记录:
Also if i change second from 58 to 56 , i got 5 results!!! 另外,如果我将秒数从58更改为56,则会得到5个结果!
Trying to rebuild of index by this query : 尝试通过此查询重建索引:
alter index all on Availibility rebuild
But the results are same and i have 4 records for some seconds. 但是结果是一样的,我有4条记录持续了几秒钟。
Test Code: 测试代码:
create table Availability
(
[date] datetime not null
)
insert Availability ([date]) select '2014-07-19 02:02:57.000'
union select '2014-07-19 02:03:57.000'
union select '2014-07-19 02:04:57.000'
union select '2014-07-19 02:05:57.000'
union select '2014-07-19 02:06:57.000'
union select '2014-07-19 02:07:57.000'
union select '2014-07-19 02:08:57.000'
union select '2014-07-19 02:09:57.000'
union select '2014-07-19 02:10:57.000'
union select '2014-07-19 02:11:57.000'
union select '2014-07-19 02:12:57.000'
declare @startDate datetime = '2014-07-19 02:07:58.000'
, @endDate datetime = '2014-07-19 02:12:58.000'
select *
from Availability
where [date] between @startDate and @endDate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.