cancel
Showing results for 
Search instead for 
Did you mean: 

A column of data is split and displayed in multiple rows

ximen
Participant
0 Kudos
1,187

have a table tb, follows: id value


1 aa,bb

2 aaa,bbb,ccc

Split the value column by id, and the results are as follows:

id value


1 aa

1 bb

2 aaa

2 bbb

2 ccc

*/

create table tb(id int,value varchar(30))

insert into tb values(1,'aa,bb')

insert into tb values(2,'aaa,bbb,ccc')

go

thanks!

justin_willey
Participant

What have you tried so far?

VolkerBarth
Contributor
0 Kudos

Oops, I overlooked that important comment:(

Accepted Solutions (0)

Answers (1)

Answers (1)

VolkerBarth
Contributor

I'm not sure I understand your question but I guess you are asking for

select tb.id, sp.row_value
from tb cross apply sa_split_list(tb.value, ',') sp
order by 1, 2