2016-05-31 26 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))