Transpose Column to row
create table #temp
(timeId int, dim1Id int, dim2Id int, Value decimal(25,10))
insert into #temp
values
(1, 1, 1, 111)
,(1, 1, 2, 112)
,(1, 2, 1, 121)
,(1, 2, 2, 122)
,(2, 1, 1, 211)
,(2, 1, 2, 212)
,(2, 2, 1, 221)
,(2, 2, 2, 222)
select dim1Id, dim2Id, [1], [2]
from
(select * from #temp) as sourceTable
pivot
(sum(Value) for TimeId in ([1], [2])) as pivotTable
drop table #temp
Sponsored Links