>DECLARE @test TABLE (Id uniqueidentifier default newID(), ColumnId int, RowId INT) >INSERT @test ( ColumnId, RowId ) VALUES ( 1,1 ) >INSERT @test ( ColumnId, RowId ) VALUES ( 1,2 ) >INSERT @test ( ColumnId, RowId ) VALUES ( 2,1 ) >INSERT @test ( ColumnId, RowId ) VALUES ( 2,2 ) >SELECT * FROM @test > >SELECT RowID, > cast([1] as uniqueidentifier) as Column1, > cast([2] as uniqueidentifier) as Column2 >from (select cast(Id AS BINARY(16)) AS id, columnId, rowID FROM @test) tmp >pivot >( > max( id ) > for columnID in ([1],[2]) >) AS pvt >I'm don't think it works if ColumnId and RowId are actually uniqueidentifiers to start with....
DECLARE @col1 uniqueidentifier SET @col1 = '4D7CA12C-FC05-40F8-A2DB-83CB71FF82C4' DECLARE @col2 uniqueidentifier SET @col2 = 'E751DF43-2E16-480D-9C40-34CF139ABDAF' DECLARE @row1 uniqueidentifier SET @row1 = 'FB37F155-7F52-438E-B6B8-93258F832DAB' DECLARE @row2 uniqueidentifier SET @row2='EB2ADCEF-0123-4FB9-A0CF-42D4576B42BD' DECLARE @test TABLE (Id uniqueidentifier default newID(), ColumnId uniqueidentifier, RowId uniqueidentifier) INSERT @test ( ColumnId, RowId ) VALUES ( @col1, @row1 ) INSERT @test ( ColumnId, RowId ) VALUES ( @col2, @row1 ) INSERT @test ( ColumnId, RowId ) VALUES ( @col1, @row2 ) INSERT @test ( ColumnId, RowId ) VALUES ( @col2, @row2 )>But think twice, should you do this. Probably there is a better way using apply or Linq.