you can either use pivot or this:-SELECT CompanyId,MAX(CASE WHEN TimeId='TimeId1' THEN KeyValue1 ELSE NULL END) AS [KeyValue1(TimeId1)],MAX(CASE WHEN TimeId='TimeId2' THEN KeyValue1 ELSE NULL END) AS [KeyValue1(TimeId2)],MAX(CASE WHEN TimeId='TimeId1' THEN KeyValue2 ELSE NULL END) AS [KeyValue2(TimeId1)],MAX(CASE WHEN TimeId='TimeId2' THEN KeyValue2 ELSE NULL END) AS [KeyValue2(TimeId2)],...FROM YourTableGROUP BY CompanyId