In general, I suspect that there is usually data that cannot be converted to a column, and will use the case statement, which checks it is converted first:
SELECT CASE WHEN ISDATE(mycolumn)=1 THEN CONVERT(Date, mycolumn, [style]) END FROM mytable
I believe Convert
relies on setting the SQL Server date format. Check your dateformat setting with DBCC USEROPTIONS
.
I suspect you will set the dateformat to dmy
, this will understand:
SET DATEFORMAT dmy GO
If even then this does not work, you cannot find a style that matches your data, and if your data is in a format with a sequence, then you need to build it for manual string manipulation (do not do this if you can help).
source share