2016-05-31 25 views
-2

我目前使用過濾器從日期和日期之間的日期中過濾掉表中的數據。而目前使用的在Microsoft SQL上過濾日期

Select * FROM [Snapshot].[dbo].[ABCVIEW] where (getdate() >= fromdate and (todate = '1900-01-01 00:00:00.000')) or getdate() between fromdate and todate 

有TODATE WHERE條件也有今天的日期使用任何過濾器

enter image description here

,但與過濾器,我使用我之前是無法看到的TODATE = 2016-05-31 00:00:00.000。我試圖添加

todate<= getdate() 

進入過濾器,但仍然沒有用。在結果中,我無法看到今天的日期,例如:todate = 2016-05-31 00:00:00.000請幫忙。

+1

純英格蘭請解釋你希望返回的標準是什麼。 –

回答

1

GETDATE返回當前時間,如果你想包括昨天午夜從GETDATE()減1,它大於2016-05-31 00:00:00.000這樣:

Select * 
FROM [Snapshot].[dbo].[ABCVIEW] 
where (getdate() >= fromdate 
    and (todate = '1900-01-01 00:00:00.000')) 
     or getdate()-1 between fromdate and todate 
0

如果轉換爲DATE,你得到的只是日期.. .....

SELECT Convert(date, getdate()) 

所以,你可以利用之間

....... 
CONVERT(Date, fromDate) and CONVERT(Date, DateAdd( d, 1, toDate))