Hi
I would like to split a column containing comma-delimiter data into many columns.
e.g
TheFruit
Apple,Pear,Kiwifruit,Orange
to
Fruit1 Fruit2 Fruit3 Fruit4
Apple Pear Kiwifruit Orange
This is like a split function, but the results appear in columns not in rows.
Here is the sample data in code
if object_id('tempdb..#Fruit') is not null then drop table #Fruit
create table #Fruit
(
TheFruit varchar(100)
)
insert into #Fruit values ('Apple,Pear,Kiwifruit,Orange')
select * from #Fruit
In my real life data there is 10 items in the TheFruit column, so parsename can't be used, and it would be a nightmare using lots of substrings and charindexs. Does any one know how to do this?
Thank you for your help
Mark
I would like to split a column containing comma-delimiter data into many columns.
e.g
TheFruit
Apple,Pear,Kiwifruit,Orange
to
Fruit1 Fruit2 Fruit3 Fruit4
Apple Pear Kiwifruit Orange
This is like a split function, but the results appear in columns not in rows.
Here is the sample data in code
if object_id('tempdb..#Fruit') is not null then drop table #Fruit
create table #Fruit
(
TheFruit varchar(100)
)
insert into #Fruit values ('Apple,Pear,Kiwifruit,Orange')
select * from #Fruit
In my real life data there is 10 items in the TheFruit column, so parsename can't be used, and it would be a nightmare using lots of substrings and charindexs. Does any one know how to do this?
Thank you for your help
Mark