This is very close, but not the same as a post of "Concatenate many rows into a single text string" Concatenate many rows into a single text string?
But what I needed, because the tables/rows had many of the same names, I only wanted the DISTINCT names showing up. So with some help from the above post as well as google I was able to pull it off...
171444 ACTIVE,ACTIVE,ACTIVE,ACTIVE,ACTIVE,ACTIVE,ACTIVE,ACTIVE
169171 RETIRED,RETIRED,RETIRED,RETIRED,RETIRED
173648 RETIRED,RETIRED,RETIRED,RETIRED,INELIGIBLE,INELIGIBLE
What I want though is:
171444 ACTIVE
169171 RETIRED
173648 RETIRED,INELIGIBLE
I think I nailed it:
Select distinct ST2.EmployeeID,
substring((Select DISTINCT (',' + ( ST1.AccrualStatus )) AS [text()]
From dbo.Plan2 ST1
Where ST1.EmployeeID = ST2.EmployeeID
For XML PATH ('')),2, 1000) [Plan2]
From dbo.Plan2 ST2
The second DISTINCT was required in the SUBSTRING to make sure we only returned one occurrence value for each value.