You can do a little variation of a Pivot for this one as follows:--Creating TableCreate Table Ex(EventID int, Attendee Varchar(30) )--Inserting Sample DataInsert Into ExSelect 13350, 'John Hart'Union ALLSelect 13350, 'David Smith'Union ALLSelect 13350, 'Jane Doe'Union ALLSelect 13353, 'John Hart'Union ALLSelect 13353, 'David Smith'Union ALLSelect 13353, 'Jane Doe'Union ALLSelect 13357, 'John Hart'Union ALLSelect 13357, 'David Smith'Union ALLSelect 13357, 'Jane Doe'Union ALLSelect 13360, 'John Hart'Union ALLSelect 13360, 'David Smith'Union ALLSelect 13360, 'Jane Doe'--Static PivotSelect EventID, [Name1] + ', ' + [Name2] + ', ' + [Name3] As Attendees From (Select *, 'Name' + Cast(ROW_NUMBER() Over (Partition By EventId Order By (Select NULL) ) As Varchar(10) ) As rn From Ex) As aPivot(Max(Attendee) For rn IN ([Name1], [Name2], [Name3]) ) As Pvt--Dynamic PivotDeclare @cols varchar(max), @sql varchar(max), @cols1 varchar(max)Declare @temp Table(Cols varchar(10) )Insert Into @tempSelect Distinct rn From (Select *, 'Name' + Cast(ROW_NUMBER() Over (Partition By EventId Order By (Select NULL) ) As Varchar(10) ) As rn From Ex) As aSelect @cols = Coalesce(@cols + ', ', '') + QUOTENAME(Cols) From @tempSelect @cols1 = Coalesce(@cols1 + '+'', ''+', '') + QUOTENAME(Cols) From @tempSet @sql = 'Select EventID, '+@cols1+' As Attendees From (Select *, ''Name'' + Cast(ROW_NUMBER() Over (Partition By EventId Order By (Select NULL) ) As Varchar(10) ) As rn From Ex) As a Pivot (Max(Attendee) For rn IN ('+@cols+') ) As Pvt'Execute (@sql)
N 28° 33' 11.93148"E 77° 14' 33.66384"