Why would the following SQL cause the error?
SqlException: The conversion of a date data type to a datetime data type resulted in an out-of-range value.
I believe it has to do with the DATEDIFF
and the type of DATE for 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,
I found the issue. The date on an event was set to 0209-06-01
.