I need to change the date format of a char(10) field to char(10) style 110. What is the most efficient way. This is sql 2005. Since the dates are consistent I suppose that I could use substring but is there a better way?
ex.05122008 change to 05-12-2008
Microsoft DevelopmentMicrosoft SQL ServerMicrosoft SQL Server 2005
SET date_column = STUFF(STUFF(date_column, 3, 0, '-'), 6, 0, '-')
SELECT date_column, STUFF(STUFF(date_column, 3, 0, '-'), 6, 0, '-')
SELECT '05122008' AS date_column
) AS test_data
Btw, odd format, since of course it won't sort correctly like that.