Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Columns in Row

0 views
Skip to first unread message

Rahul

unread,
Nov 23, 2009, 2:29:46 AM11/23/09
to
Hi,
I have following challenge

Source:

Create Table Foo
(
Col1 Int,
Col2 Int,
Col3 Int
Col4 Int
)
Go

Insert into Foo
Select 10, 70, 30, 90

Output Required
Col1, 10
Col2, 70
Col3, 30
Col4, 90

Rahul

Plamen Ratchev

unread,
Nov 23, 2009, 9:46:18 AM11/23/09
to
You can use the UNPIVOT operator:

SELECT col, value
FROM Foo
UNPIVOT
(value FOR col IN (Col1, Col2, Col3, Col4)) AS U;

--
Plamen Ratchev
http://www.SQLStudio.com

0 new messages