sql - Group one Column CSV -
i trying resource , assosiate skills want ask if there away group skill in 1 column csv
id skills
1, reading,writing 2,programing, reading
select resources.id, skills.description resources inner join skills_resources on resources.id = skills_resources.resourceid inner join skills on skills_resources.skillid = skills.id
in order concatenate multiple rows need use for xml path
:
select distinct r.id, stuff( (select ', ' + cast(s.description varchar(50)) skills s inner join skills_resources sr on sr.skillid = s.id r.id = sr.resourceid xml path ('')) , 1, 1, '') skills resources r;
see sql fiddle demo.
you use cross apply
for xml path
:
select distinct r.id, left(s.skill, len(s.skill)-1) skills resources r cross apply ( select s.description + ', ' skills s inner join skills_resources sr on sr.skillid = s.id r.id = sr.resourceid xml path('') ) s (skill);
see sql fiddle demo
Comments
Post a Comment