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
 General SQL Server Forums
 New to SQL Server Programming
 split one column into multiple columns

Author  Topic 

apvani
Starting Member

6 Posts

Posted - 2011-10-26 : 09:04:58
Hi,

I have a column in database that has some data seperated by space

example: 0001 000 0000
0002 01010 000

I want to split them into three seperate columns in a report I am generating using sql.

Any help on this is really appriciated.

Thank you

Cindyaz
Yak Posting Veteran

73 Posts

Posted - 2011-10-26 : 09:10:50
Write a split function.

[url]http://searchsqlserver.techtarget.com/tip/Using-split-delimiter-separated-lists-in-SQL-Server [/url]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-26 : 09:17:00
use fnParseString() from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 03:10:13
if format is consistent with always three parts, use

select parsename(replace(yourcolumn,' ','.'),3) as first,
parsename(replace(yourcolumn,' ','.'),2) as second,
parsename(replace(yourcolumn,' ','.'),1) as third
from table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-10-27 : 08:44:46
Another method
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/11/splitting-delimited-data-to-columns-set-based-approach.aspx

Madhivanan

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

- Advertisement -