Hello,
Can anyone explain the difference between a SQL Server 2005 conversion from varchar and nvarchar to datetime or smalldatetime? Look at the following example:
SELECT DISTINCT HEDTE, CONVERT(smalldatetime, HEDTE, 112)
FROM ECHECL
ORDER BY HEDTE
This returns the error: Msg 8115 arithmetic overflow converting expression to smalldatetime data type. The column HEDTE is of type nvarchar(8).
The following modification solves the problem, but I don't understand why:
SELECT DISTINCT HEDTE, CONVERT(smalldatetime, CAST(HEDTE AS varchar(8)), 112)
FROM ECHECL
ORDER BY HEDTE
This returns the correct results. The data underneath has not changed. What is the difference between converting the same string from varchar to smalldatetime and from nvarchar to smalldatetime, when I even provide the input format of the string expression in the CONVERT function?
Any explanation is very appreciated!
Thanks,
Sebastian
PS: For reference the result set of the succesful query is attached as file.
Start Free Trial