我需要搜索在特定日期輸入的行。SQL Server 2008搜索日期
但是,我需要搜索的列的數據類型是datetime
,而參數的數據類型是Date
。
我可以使用查詢像
Select result
from table
where
convert(date, Mycolumn) = @selectedDate
,但會影響查詢的SARGability並不會使用在mycolumn
創建的索引。
我嘗試使用下面的查詢:
Select result
from table
where
Mycolumn
BETWEEN @selectedDate AND Dateadd(s, -1, Dateadd(D, 1, @selectedDate))
然而,這並不工作,因爲@selectedDate
是日期型,第二,不能添加或刪除。
有人可以幫我一個工作查詢嗎?
謝謝。
看看這裏:[http://stackoverflow.com/questions/4156011/how-to-select-rows-for-a-specific-date-ignoring-time] [1] – ParPar 2012-02-06 07:29:54