Solved

Access Transform CrossTab Query with Default Column Names not Row Names

Posted on 2014-12-07
4
164 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 34

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now