Conversion failed when converting the %ls value '%.*ls' to data type %ls.

Error Message:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the %ls value ‘%.*ls’ to data type %ls.

Severity level:
16.

Description:
This error message appears, when SQL Server encounters an error while converting from one type into another type.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Error of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The rules for converting (implicit and explicit) data types and the rules for data type precedences must be followed.

Versions:
All versions of SQL Server.

Example(s):
SELECT ‘20070217 00:00:00’ + 12

Remarks:
In the above example we try to combine a string and an integer value. Because of the higher data type precedence of integer values over string values, SQL Server tries to convert the string value into a value of type integer. This raises the error. This example uses implicit conversion and is a frequent error when dynamic SQL is used. But even when explicit conversion is used this is a frequent error.

]]>

Leave a comment

Your email address will not be published.