sql - Group one Column CSV -


i trying resource , assosiate skills want ask if there away group skill in 1 column csv enter image description here

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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -