This is my data. I'm trying to convert vertical data to horizontal data. I tried using PIVOT, but I don't have a column to be used as aggregate.
I don't need to use PIVOT, but it's the operator I've used for this kind of thing. I also considered it since I know all possible GroupIds.
Name      GroupId
Joe       B1
John      B2
Mary      C1
Lisa      D2
Joe       D2
The result would be something like this. I have to concatenate all the strings for each name:
Name   B1   B2   C1   D2
Joe    B1             D2
John        B2        
Mary             C1
Lisa                  D2
I was thinking of something like this, but I knew it will not produce the desired results.
declare @table table
(
    Name varchar(10),
    GroupId varchar(2)
)
insert into @table
select 'Joe', 'B1' union
select 'John','B2' union
select 'Mary','C1' union
select 'Lisa','D2' union
select 'Joe','D2'
    select *
    from 
    (
      select Name, GroupId
      from @table
    ) src
    pivot
    (
      min(Name)
      for GroupId in ([B1], [B2], [C1], [D2])
    ) piv;
 
     
     
    