In SQL Server, I want a query to show like group of items with single main item and multiple group items separated with commas.
e.g. When 'ATLAS' is the main item then the group of group items is 'BAND SEALER SPARE','30F SPARES'...
In SQL Server, I want a query to show like group of items with single main item and multiple group items separated with commas.
e.g. When 'ATLAS' is the main item then the group of group items is 'BAND SEALER SPARE','30F SPARES'...
I think you simply want string_agg()
:
select item,
string_agg([Group], ',') within group (order by [Group]) as groups
from t
group by item;