为什么我只选择去年的数据范围来获得今年的价值?如何操作数据范围?

时间:2016-06-24 23:56:09

标签: sql tsql datetime

考虑:

select AccountingDate
from Test_Plaza_ProductionReport
where AccountingDate >='2015/06/24' AND AccountingDate <= '2016/06/24 23:59:59.999'
    And My Accounting Date only in 2016, whats with 2015?

Enter image description here

3 个答案:

答案 0 :(得分:0)

也许他们会在你的结果集中进一步下降?或者,尝试在2015年搜索值:

SELECT AccountingDate 
FROM Test_Plaza_ProductionReport 
WHERE AccountingDate >='2015/06/24' AND AccountingDate < '2016/01/01 00:00:00.000' 

答案 1 :(得分:0)

应该如何

select AccountingDate 
from Test_Plaza_ProductionReport 
where AccountingDate <= CAST('2016/06/24' AS DATETIME) 
  AND AccountingDate >= CAST('2015/06/24' AS DATETIME)

答案 2 :(得分:0)

尝试以适当的格式保留日期

Select AccountingDate 
 From  Test_Plaza_ProductionReport 
 Where AccountingDate between '2015-06-24' AND '2016-06-25' and AccountingDate<'2016-06-25'
 Order By AccountingDate