Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PIVOT SQL

Status
Not open for further replies.

747576

Programmer
Jun 18, 2002
97
GB
Hi there,

Can someone help me with some sql code. I have a table which has data in rows and I want pivot this data into columns.
i.e
ID1 NAME1 VALUE
ID1 NAME2 VALUE
ID1 NAME3 VALUE
ID2 NAME1 VALUE
ID2 NAME2 VALUE

And I want?

ID NAME1 NAME2 NAME3
--------------------
ID1 VALUE VALUE VALUE

I'd appreciate some help. Many Thanks.
 
SELECT A.ID, A.VALUE NAME1, B.VALUE NAME2, C.VALUE NAME3
FROM yourTable A
INNER JOIN yourTable B ON A.ID = B.ID
INNER JOIN yourTable C ON A.ID = C.ID
WHERE A.NAME = 'NAME1' AND B.NAME = 'NAME2' AND C.NAME = 'NAME3'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top