DATEDIFF 导致将日期数据类型转换为日期时间数据类型导致值超出范围
DATEDIFF causing The conversion of a date data type to a datetime data type resulted in an out-of-range value
为什么下面的SQL会导致错误?
SqlException: The conversion of a date data type to a datetime data type resulted in an out-of-range value.
我认为这与 DATEDIFF
和 StartDate
的日期类型有关?
(CASE WHEN @OrganizationId IS NOT NULL AND ev.EndDate >= @SortStartDate THEN 0
WHEN ev.StartDate >= @SortStartDate THEN 1
ELSE DATEDIFF(DAY, ev.StartDate, -1)
END) ASC,
我发现了问题。事件的日期设置为 0209-06-01
.
为什么下面的SQL会导致错误?
SqlException: The conversion of a date data type to a datetime data type resulted in an out-of-range value.
我认为这与 DATEDIFF
和 StartDate
的日期类型有关?
(CASE WHEN @OrganizationId IS NOT NULL AND ev.EndDate >= @SortStartDate THEN 0
WHEN ev.StartDate >= @SortStartDate THEN 1
ELSE DATEDIFF(DAY, ev.StartDate, -1)
END) ASC,
我发现了问题。事件的日期设置为 0209-06-01
.