Home > SQL > Convert column into rows in SQL 2005 using Pivot/Unpivot

Convert column into rows in SQL 2005 using Pivot/Unpivot

Before

ID

Quantity 1

Quantity 2

Quantity 3

145

5

14

3

146

12

13

14

148

44

2323

NULL

SELECT *

FROM

(SELECT RFQDetID, Quantity1, Quantity2, Quantity3

FROM RFQDetail where RFQID = 230) p

UNPIVOT

(Value FOR Old_Col_Header IN

(Quantity1, Quantity2, Quantity3)

)AS unpvt;

GO

After applying unpivot data look like

ID

Value

Old_Col_Header

145

5

Quantity1

145

14

Quantity2

145

3

Quantity3

146

12

Quantity1

146

13

Quantity2

146

14

Quantity3

148

44

Quantity1

148

2323

Quantity2


Comments are closed.

TOP