Hi
I have a table with 5 million records of dates stored as char(10) with format yyyy/mm/dd. I need to convert these to datetime, so I use:
UPDATE [Database].[dbo].[Table]
SET [DoB]=convert(datetime,[DoBText],103)
GO
But I get the error:
"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
Now, I've tried fixing the data so this doesn't happed - i.e. no "yyyy" below 1900 or above 2000, no "dd" above 30 (28 for Feb), no "mm" above 12 or below 0. No NULLs.
Still the conversion fails.
Is there any way I can let SQL to skip the conversion on an error and just go on?
E.g. something like:
SET [DoB]= try to do [DoB]=convert(datetime,[DoBText],103) if fails SET [DoB] = NULL
Thanks Karl