Pivot sample

1

Please login or register to vote for this query.

(click on this box to dismiss)

Reverse Engineering Meta

Q&A about the site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation

create table #temp
(
  accountNumber int,
  financialPeriod int,
  endingBalanceLC int
)

insert into #temp values (101, 1, 100)
insert into #temp values (101, 2, 200)
insert into #temp values (102, 2, 200)
insert into #temp values (103, 3, 150)
insert into #temp values (103, 3, 150)

select accountNumber
  , [financialPeriod1] = sum([1])
  , [financialPeriod2] = sum([2])
  , [financialPeriod3] = sum([3])
from #temp
pivot
(
  sum(endingBalanceLC)
  for financialPeriod in([1], [2], [3])
) p
group by accountNumber

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results