1. Code
select *
from
(
select Item1,Item2,Item3, Item4, Quantity -- quantity (datatype int)
from TblTablle1
) x
pivot
(
sum (Quantity)
for Item4 in ([A],[B],[C],[D]) ' ABCD is value record in SQL Table of Item4
) p
2. Example
* TableA
NO Month Money
1 T1 200
2 T1 100
3 T2 400
4 T3 500
5 T4 300
6 T4 250
* Using Pivot
select *
from
(
select Month,Money
from TblTableA
) x
pivot
(
sum (Money)
for Month in ([T1],[T2],[T3],[T4])
) p
* Result
T1 T2 T3 T4
Money 300 400 500 550
Nguồn: Sharecode.vn