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 2008 Forums
 Transact-SQL (2008)
 Split columns

Author  Topic 

Dan1978
Starting Member

5 Posts

Posted - 2012-09-10 : 08:37:10

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 example below of what I am trying to achieve.

If anyone could help, that would be great


Thanks in advance for your help.



Column 1
Dialler 02 MH LIAB 30-08-12 SEPT REF MB-Renewal Date Obtained/Corrected

After Split ( 4 columns)

New Column 1 New Column 2 New Column 3 New Column 4
Dialler 02 MH LIAB 30 08 12 SEPT REF MB Renewal Date Obtained/Corrected

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-10 : 08:53:27
use the fnParseString function here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-10 : 08:55:34
Use a string-splitter function such as the one described here: http://www.sqlservercentral.com/articles/Tally+Table/72993/ Copy and install the function from Fig. 21 in that article. Then you would use it as [dbo].[DelimitedSplit8K](YourStringColumn,'-')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-13 : 04:58:31
Also refer this
http://beyondrelational.com/modules/2/blogs/70/posts/10844/splitting-delimited-data-to-columns-set-based-approach.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -