Select Distinct (Select Stuff( (Select ' - ' + name From #Test t1 Where t.manager = t1.manager Order By t1.name For XML Path(''),Type) .value('text()','nvarchar(max)'),1,2,N'')) As Names From #Test t Where t.manager = 'Joe';
Glad that you already received your answer!
If your version is SQL Server 2017 and later, you could also consider to use STRING_AGG as below:
Select string_agg(name,' - ') Names from #Test where manager = 'Joe'
Names Jason - Mark
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.