0

I've got data in a column of my table just like this:

cpc > cpc > organic
cpc > organic >cpc
mail > cpc > organic

How can I split that data to different columns using '>' as a delimiter?

Keithx
  • 2,994
  • 15
  • 42
  • 71
  • 2
    http://stackoverflow.com/questions/10581772/how-to-split-a-comma-separated-value-to-columns – Paolo Costa Apr 25 '15 at 19:00
  • So when I use that script in the link- how to make a split function from a certain column? it does not work when i try Select * from fn_CSVToTable (Select Column from Table) – Keithx Apr 25 '15 at 20:43

3 Answers3

2

This is famous problem. You can use Regex through CLR imported function, but here is very usefull script. Alter spliting you can use PIVOT/UNPIVOT is you need exactly data-by-columns.

Community
  • 1
  • 1
Vladimir Semashkin
  • 1,270
  • 1
  • 10
  • 21
0
SELECT 
    PARSENAME(REPLACE(String,'>','.'),1) AS 'col1' ,
    PARSENAME(REPLACE(String,'>','.'),2) AS 'col2' ,
    PARSENAME(REPLACE(String,'>','.'),3) AS 'col3'
FROM tbl 
Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24
0

may be you can do like this also

declare @t table (name varchar(30))
insert into @t (name)values ('cpc > cpc1 > organic'),('cpc > organic1 >cpc')
select 
SUBSTRING(name,0,CHARINDEX('>',name))As Col1,
SUBSTRING(name, charindex('>', name)+1, len(name) - CHARINDEX('>', reverse(name)) - charindex('>', name))As Col2,
REVERSE(SUBSTRING(reverse(name),0,CHARINDEX('>',reverse(name))))As Col3
 from @t
mohan111
  • 8,633
  • 4
  • 28
  • 55