我试图让之间的所有记录00:00现在时间后SQL查询凡之间两个日期
如2014年2月21日00:01和2014年2月21日10:41(现在的时间)
Select * from TableName Where Time >=??? and Time < Getdate()
之间
我试图让之间的所有记录00:00现在时间后SQL查询凡之间两个日期
如2014年2月21日00:01和2014年2月21日10:41(现在的时间)
Select * from TableName Where Time >=??? and Time < Getdate()
之间
Select * from TableName Where Time between ??? and Getdate()
Select * from TableName Where DateDiff(day,TimeColumn,getdate())
between 0 and 0
你可以使用'DateDiff(day,TimeColumn,getdate())= 0' –
'datediff'的问题是它会使优化器无法使用'TimeColumn'上的任何现有索引。作为一种很好的启发式/经验法则,避免在列上使用函数。 –
如果你在SQL 2008或更高版本,你可以这样做的FF:
select *
from tablename
where cast([Time] as date) = getdate()
and cast([Time] as time) >= '10:41'
由于cast
使谓词不可SARGable,因此这不会超级高性能。如果这是您设想经常进行的操作,则可以将持久计算的列添加到为您执行强制转换的表中。
Select * from TableName Where Time between cast(GETDATE() as DATE) and Getdate()
使用地点之间的时间???和Getdate() –
尝试:select * from table where time> = '21 .02.2014 00:01'and time <'21 .02.2014 10:41'; – Punter015
你有问题吗?你的语法没有问题 – Leo