Solved

Access Transform CrossTab Query with Default Column Names not Row Names

Posted on 2014-12-07
4
170 Views
Last Modified: 2014-12-08
I have a query that I would like the results to be in columns not rows, but I do not want the column names to be the row result names.

TRANSFORM First(part_id) AS FirstOfPartID
SELECT part_id, id
FROM qryqfitraceonhand
GROUP by PART_ID, ID
PIVOT part_id


Here is the query results and the how I would like the table to look.  I spent a couple hours looking for answers and I think I may need code for this.

I can modify the data in excel as well, if that is easier, but I do not know how to do that either.

TIA,

Faunna Bartlett
ExpertsExchangeCrossTabQuery.JPG
0
Comment
Question by:cadencedba
  • 2
4 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40486448
I would do this as two queries, just to make the coding easier:

Query 1 (which I've called qryqfitraceonhand2):

SELECT A.Part_ID, A.ID, A.TraceQty, A.Qty_on_Hand, Count(B.ID) AS CountOfID
FROM qryqfitraceonhand AS A INNER JOIN qryqfitraceonhand AS B ON (A.Part_ID = B.Part_ID) AND (A.ID >= B.ID)
GROUP BY A.Part_ID, A.ID, A.TraceQty, A.Qty_on_Hand;

Open in new window


Query 2:

SELECT A.Part_ID, A.ID AS Trace1, A.TraceQty AS Trace1_Qty, B.ID AS Trace2, B.TraceQty AS Trace2_Qty, C.ID AS Trace3, C.TraceQty AS Trace3_Qty, D.ID AS Trace4, D.TraceQty AS Trace4_Qty
FROM (((SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 1) AS A LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 2)  AS B ON A.Part_ID = B.Part_ID) LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 3)  AS C ON A.Part_ID = C.Part_ID) LEFT JOIN (SELECT * FROM qryqfitraceonhand2 WHERE CountOfID = 4)  AS D ON A.Part_ID = D.Part_ID;

Open in new window

0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40486449
It gives a slightly different answer, because there are some typos? in your data - but it gives the right answer based on your data.
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40487124
You can do this with a crosstab but you need to use two of them because a crosstab can only pivot one column at a time and then join the 2 crosstabs.   Generating dummy names for the column headers will be required but you can use the "First" option to select the values.
0
 

Author Comment

by:cadencedba
ID: 40487967
Thank you!  I used Phillips solutions.  I had done this a year ago, but forgot what I had done to get there.  I also added more columns.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question