-1

In SQL Server, I want a query to show like group of items with single main item and multiple group items separated with commas.

enter image description here

e.g. When 'ATLAS' is the main item then the group of group items is 'BAND SEALER SPARE','30F SPARES'...

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. As it stands I can barely read it. – Dale K May 26 '21 at 10:12
  • Does this answer your question? [SQL group\_concat function in SQL Server](https://stackoverflow.com/questions/8868604/sql-group-concat-function-in-sql-server) – Connor Low May 26 '21 at 16:38

1 Answers1

1

I think you simply want string_agg():

select item,
       string_agg([Group], ',') within group (order by [Group]) as groups
from t
group by item;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786