2014-02-21 165 views
0

我试图让之间的所有记录00:00现在时间后SQL查询凡之间两个日期

如2014年2月21日00:01和2014年2月21日10:41(现在的时间)

Select * from TableName Where Time >=???  and Time < Getdate() 
之间
+0

使用地点之间的时间???和Getdate() –

+0

尝试:select * from table where time> = '21 .02.2014 00:01'and time <'21 .02.2014 10:41'; – Punter015

+0

你有问题吗?你的语法没有问题 – Leo

回答

1
Select * from TableName Where Time between ??? and Getdate() 
0
Select * from TableName Where DateDiff(day,TimeColumn,getdate()) 

    between 0 and 0 
+3

你可以使用'DateDiff(day,TimeColumn,getdate())= 0' –

+0

'datediff'的问题是它会使优化器无法使用'TimeColumn'上的任何现有索引。作为一种很好的启发式/经验法则,避免在列上使用函数。 –

0

如果你在SQL 2008或更高版本,你可以这样做的FF:

select * 
from tablename 
where cast([Time] as date) = getdate() 
    and cast([Time] as time) >= '10:41' 

由于cast使谓词不可SARGable,因此这不会超级高性能。如果这是您设想经常进行的操作,则可以将持久计算的列添加到为您执行强制转换的表中。

0
Select * from TableName Where Time between cast(GETDATE() as DATE) and Getdate() 
相关问题