Skip to content
Advertisement

CONVERT issue in sqlserver with Msg 529 error

select CONVERT(datetime,value,103) from results

This statement is giving me a error

"Msg 529, Level 16, State 2, Line 1
Explicit conversion from data type text to datetime is not allowed."

VALUE column Datatype is TEXT in the RESULTS table.

How can i overcome the above problem. please help !

Advertisement

Answer

You can’t convert from text to datetime

You must apply two convert operations.

The first: From text to varchar

The second: From varchar to datetime

So your query will become:

SELECT CONVERT(datetime,
       CONVERT(varchar(30),value), 103)
FROM results

Plus: text datatype is deprecated for new versions of Sql Server, so I strongly advice you to change (if you can) your datatype text into varchar(max).

The DDL code to apply your change is:

ALTER TABLE results ALTER COLUMN value varchar(max)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement