Crosstab Query Help

gmatriix

Registered User.
Local time
Today, 18:15
Joined
Mar 19, 2007
Messages
365
Hello All,

I have a table that have multiple entries and I am trying to get it all on one line base off of account number.

The way the table was set up (not me) repeats the data when I run a query against it. I know I possibly can run a cross tab query that might clear this up but have a bit of trouble with it.

Here is a example how the current query is coming out.
Account NumberStatusTypeName
123456ActiveCarJoe Shmo
123456ActiveCarJane Shmo
123456ActiveCarJim Shmo
654321CancelledBusBob Change
654321CancelledBusBill Change

This is what I am trying to accomplish

Account NumberStatusTypeName 1Name 2Name 3
123456ActiveCarJoe ShmoJane ShmoJim Shmo
654321CancelledBusBob ChangeBill Change

Any Ideas?

Thanks

CG
 
Hi. Can you post a sample db with test data? I think this will need some extra steps. For example, you'll have to somehow add another column to designate Joe Shmo and Bob Change are Name 1 and Jane Shmo and Bill Change are Name 2. Without that designation, a simple Crosstab wouldn't be able to figure out what columns to generate.
 
What's the big picture? Do you really need a new field for every [Name] value? Or do you simply need every [Name] value in one record?

A cross-tab may not be the best solution, instead the ConcatRelated(http://allenbrowne.com/func-concat.html) function might work.
 
hi gmatriix,

a Crosstab query isn't going to get the results you want.

This SQL:
TRANSFORM First(MyTable.Name) AS FirstOfName
SELECT MyTable.[Account Number], MyTable.[Status], MyTable.[Type]
FROM MyTable
GROUP BY MyTable.[Account Number], MyTable.[Status], MyTable.[Type]
PIVOT MyTable.[Name];


results in this display:

crosstabData_Crosstab

Account NumberStatusTypeBill ChangeBob ChangeJane ShmoJim ShmoJoe Shmo
123456​
ActiveCarJane ShmoJim ShmoJoe Shmo
654321​
CancelledBusBill ChangeBob Change

Perhaps what you should use is a Grouped report

grouped report.png


* Name and Type are both reserved words and shouldn't be used as fieldnames
Problem names and reserved words in Access by Allen Browne
http://allenbrowne.com/AppIssueBadWord.html
 
Last edited:

Users who are viewing this thread

Back
Top Bottom