Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 split string value

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-10-22 : 12:46:31
I have column that stores a date as a char value in the following format:
20101023
How can I change this into 2010-10-23?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-22 : 12:48:24
SELECT STUFF(STUFF(datecol,7,0,'-'),5,0,'-') FROM myTable

I recommend changing the data type of that column to datetime if you can, if it's only supposed to store dates.
Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-10-22 : 17:31:31
Thank you - that's perfect.
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2010-10-22 : 18:52:19
SELECT CONVERT(DATETIME,'20101023',101)

If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -