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?
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?
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.
SELECT
PARSENAME(REPLACE(String,'>','.'),1) AS 'col1' ,
PARSENAME(REPLACE(String,'>','.'),2) AS 'col2' ,
PARSENAME(REPLACE(String,'>','.'),3) AS 'col3'
FROM tbl
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