Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

split column Expand / Collapse
Author
Message
Posted Monday, September 10, 2012 4:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, May 12, 2014 4:22 AM
Points: 13, Visits: 103
Hi, I'm trying to split a single column into a number of columns, with the split being the delimiter of '-'

I have enclosed an excel example of what I am trying to achieve.

If anyone could help, that would be great


Thanks in advance for your help.







  Post Attachments 
split.xlsx (14 views, 10.53 KB)
Post #1356639
Posted Monday, September 10, 2012 4:50 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, August 22, 2014 9:02 AM
Points: 689, Visits: 2,779
Hi

Take a look at this link:

http://www.sqlservercentral.com/articles/Tally+Table/72993/

Andy


==========================================================================================================================
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe
Post #1356648
Posted Wednesday, October 10, 2012 6:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 10, 2012 9:18 AM
Points: 2, Visits: 6
Bit of a late answer, but found this usefull when I had this same problem.
http://www.syntaxwarriors.com/2012/t-sql-splitting-strings-into-multiple-rows/


Even has an example of how to make sure that any other columns of data are moved along with the split values.
Post #1370874
Posted Wednesday, October 10, 2012 7:56 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:32 PM
Points: 13,302, Visits: 12,168
Fantastica (10/10/2012)
Bit of a late answer, but found this usefull when I had this same problem.
http://www.syntaxwarriors.com/2012/t-sql-splitting-strings-into-multiple-rows/


Even has an example of how to make sure that any other columns of data are moved along with the split values.


The article reference by Andy explains why the process at the link you posted will work but performs a lot slower.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1370933
Posted Wednesday, October 10, 2012 8:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 10, 2012 9:18 AM
Points: 2, Visits: 6
Maybe I'm reading it wrong, but short of going into CLR (which I personally try to avoid for maintainability) CTE dosen't seem to be much slower?

I mostly liked the link I provided for it's simplicity, but then again I'm not in need of break neck speeds, my script will only be running about once per day when noone else is logged in, so a couple of extra milliseconds wont matter ;)
Post #1370977
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse