首页 > 解决方案 > 当针对日期时间列查询少于 90 天时,如何“忽略”1/1/1753?

问题描述

select case when [Estimated Return Date] <= DATEDIFF(day, -90, GETDATE()) then 
'90 Days or Less To Estimated Return Date' else '' end as 'Alert', [No_]

from [Rental Header]
where [Estimated Return Date] != '1/1/1753'

这样做的问题是它通过添加 where 子句消除了我需要查看的许多记录。

标签: sql-serverdatetimedatediff

解决方案


作为绷带,您可以这样做(对于 1753,最好使用 NULL):

select case when [Estimated Return Date] > '17530101' AND

       [Estimated Return Date] <= DATEDIFF(day, -90, GETDATE()) 
     then '90 Days or Less To Estimated Return Date' 
     else '' end as [Alert], [No_]
from [Rental Header];

推荐阅读