-
Tom Cooper 8,026 Reputation points
2021-04-22T18:24:25.223+00:00 Select Distinct (Select Stuff( (Select ' - ' + name From #Test t1 Where t.manager = t1.manager Order By t1.name For XML Path(''),Type) .value('text()[1]','nvarchar(max)'),1,2,N'')) As Names From #Test t Where t.manager = 'Joe';
Tom
Hi InigoMontoya-1790,
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'
Output:
Names
Jason - Mark
Best regards
Melissa
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.