Saw a few threads on this but I have a specific instance where I am trying to do the conversion within an ALTER TABLE statement.
ALTER TABLE Leads
ALTER COLUMN [Created Date] Date
This is throwing an error:
Msg 241, Level 16, State 1, Line 34
Conversion failed when converting date and/or time from character string.
The statement has been terminated.
Created Date is currently set as (varchar(max), null)
You could standardize the date format. Something like this:
The third argument is for the MM/DD/YYYY format mentioned in a comment. This will convert the value to a date -- if it can -- and to
NULL
otherwise. Then, SQL Server will use its default formats to convert back to a string.NOTE: If you do this, be sure you back up the table, so you don't lost the information in the column!
Then, your code should work:
You can find the rogue values by using:
i think you must to create temp table and then insert all of records into temp table then rename temp table and original table
As per Jarlh: