Conversion failed when converting datetime from binary/varbinary string

Error Message:
Msg 210, Level 16, State 1, Line 3
Conversion failed when converting datetime from binary/varbinary string.

Severity level:
16.

Description:
This error message appears when you try to convert an invalid BINARY(VARBINARY) string to a value of type DATETIME.

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 (VAR)BINARY string must either be valid and convertible to DATETIME.

Versions:
All versions of SQL Server

Example(s):
DECLARE @bin BINARY(8)
SELECT @bin = CAST(GETDATE() AS BINARY(8))
SELECT CAST(@bin + CAST(1 AS BINARY(1)) AS DATETIME)
–or
SELECT CAST(0x002D248F00000000 AS DATETIME)

Remarks:
In the first example above the conversion to DATETIME is illegal because of the addition of two binary values.

In the second example is the binary string as such valid, but the resulting DATETIME value exceeds the upper limit of the DATETIME data type. This raises the error.




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |