Could someone please explain me, why I get the error
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
when I execute the following code on SQL Server 2017. I get the error only for .999 milliseconds
SELECT CAST('9999-12-31 23:59:59.999' AS DATETIME)
Result:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Then I tried:
SELECT CAST('9999-12-31 23:59:59.998' AS DATETIME)
Result: 9999-12-31 23:59:59.997
Then I tried:
SELECT CAST('9999-12-31 23:59:59.997' AS DATETIME)
Result: 9999-12-31 23:59:59.997