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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot/ crosstab a table 1

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
Is it possible to pivot a multi-column table? All the TRANSFORM examples I find just use 1 column. So, for example, you have

tblPersons

personid/height in inches/weight in lbs/age in yrs

1/72/185/32
2/64/129/43
3/69/167/37

I need a query that will do

...........person
...........1/2/3
height 72/64/69
weight 185/129/167
age 32/43/37

Anybody know to make an Access query how to do this simple flip?
 
try this:

step (1) - create a query named qryPersonsUnion that looks like this:

SELECT personid,"Height" as nm, height as nbr FROM tblPersons
union all
SELECT personid, "Weight" as nm, weight FROM tblPersons
UNION ALL
SELECT personid, "Age" as nm, age FROM tblPersons;

step (2) - create a query named qryPersonsPivot that looks like this:

TRANSFORM max(nbr) AS nbr1
SELECT nm
FROM qryPersonsUnion
GROUP BY nm
PIVOT personid;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top