在sql查询的where子句中检查当前日期的最佳方法 [英] Best way to check for current date in where clause of sql query
本文介绍了在sql查询的where子句中检查当前日期的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找出检查当前日期的日期字段的最有效(最佳性能)方法.目前我们正在使用:
I'm trying to find out the most efficient (best performance) way to check date field for current date. Currently we are using:
SELECT COUNT(Job) AS Jobs
FROM dbo.Job
WHERE (Received BETWEEN DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0)
AND DATEADD(d, DATEDIFF(d, 0, GETDATE()), 1))
推荐答案
WHERE
DateDiff(d, Received, GETDATE()) = 0
正如对此答案的评论中所述,这不是理想的解决方案.也请检查此线程中的其他答案.
As lined out in the comments to this answer, that's not an ideal solution. Check the other answers in this thread, too.
这篇关于在sql查询的where子句中检查当前日期的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文