sql server - T-SQL: Combine rows to one row -


i have following table:

number  word ======  ==== 1       aaa 2       bbb 2       cccc 4       cccc 4       bbb 4       aaa 

now want create new table, "number" occurs in 1 row. corresponding values in "word" should converted comma sepeareted string.

the result table:

number  word ======  ==== 1       aaa 2       bbb,cccc 4       ccccc,bbb,aaa 

how can solved t-sql? in advance.

i started may post mine too...

create table #test (     id tinyint     ,word varchar(20) ); insert #test values (1,'aaa') ,(1,'bbb') ,(2,'abc') ,(2,'def') ,(2,'ghi') ,(3,'zzz');  select distinct a.id ,stuff((     select         ',' + b.word     #test b     a.id = b.id      xml path('') ),1,1,'') [contains] #test 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -