>declare @Cols varchar(max), @SQL nvarchar(max), @ColsWithNames varchar(max) > >select @Cols = coalesce(@Cols + ',','') + QUOTENAME(ColumnID), >@ColsWithNames = coalesce(@ColsWithNames + ', ','') + QUOTENAME(ColumnID) + ' as Column' + CAST(Row as varchar(10)) > from (select CAST(ColumnID as varchar(36)) as ColumnID, >ROW_NUMBER() over (order by CAST(ColumnID as varchar(36))) as Row from test50 group by CAST(ColumnID as varchar(36))) X > >--print @Cols > >set @SQL = 'select RowID, ' + @ColsWithNames + >' from (select cast(ID as varchar(36)) as ID, cast(ColumnID as varchar(36)) as ColumnID, RowID from test50) src >PIVOT (min(ID) FOR ColumnID IN (' + @Cols + ')) pvt' > >--print @SQL > >execute (@SQL)Thank you! Had to tweak it a little to get it to work with my tables but it works great. I'm still pawing through it to understand the pivot bit though.....