我想限制的报告通过日期B.从日期返回记录的正确性这是我一直在做的事情:限制日期范围与MS SQL/SQL Server 2005的
declare @startDate varchar(20)
declare @endDate varchar(20)
set @startDate = '01/01/2008'
set @endDate = '04/01/2008'
-- test what are the start and end dates
select min(date),max(date) from view_Inspections
where date between @startDate and @endDate
...我被告知从3月31日的凌晨1点到11点59分回复了记录(当没有时间时,默认是午夜)。但是我注意到了一个差异,就是如果一个记录的时间是00:00:00,那么它将成为这个集合的一部分。
是否有这样做所以它会返回正是我想要的日期范围的更精确的方式*
我试着使用时间:
declare @startDate varchar(20)
declare @endDate varchar(20)
set @startDate = '01/01/2008 00:00:00'
set @endDate = '04/01/2008 11:59:59'
-- test what are the start and end dates
select min(date),max(date) from view_Inspections
where date between @startDate and @endDate
...但我注意到了一些靠不住的: SQL Server将把hundreth-second增加一半。因此,如果我晚于11:59:29使用任何时间,我会得到4月1日的纪录(ha!April Fool's record!grr)。这是为什么?
- (我觉得肯定有我新,在此感谢您的帮助。!)
谢谢!这有很大帮助。 @ G-Mastros:这是SmallDateTime - 感谢您解释这种数据类型的行为! – aesdanae 2009-01-05 21:19:17