sql server - Comma separated results in SQL -


i have following code create comma delimited list results:

declare @liststr varchar(max) select @liststr = coalesce(@liststr+', ' ,'') + institutionname education studentnumber= '111' select @liststr 

the problem creating 1 massive comma delimited line. need return comma separated list per row.

so if simon has been part of 2 institutions, expect:

"institution1, institution2" 

as didnt supply clause expect results show each row in database.

use for xml path('') , stuff() follows gives same comma seperated result

select  stuff((select  ',' + institutionname             education ee              ee.studentnumber=e.studentnumber             order sortorder         xml path('')), 1, 1, '') liststr  education e group e.studentnumber 

here fiddle


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -