Help with Crosstab Query

Hi Experts,

I have a working Crosstab query:

TRANSFORM Count(Items.ItemCategory) AS CountOfItemCategory
SELECT CLIENTS3.ClientID
FROM Items INNER JOIN (CLIENTS3 LEFT JOIN [Item Transactions] ON CLIENTS3.ClientID = [Item Transactions].CustomerID) ON Items.ItemID = [Item Transactions].ItemID
GROUP BY CLIENTS3.ClientID
PIVOT Items.ItemCategory;

The output looks OK, but I want the query to also include records in CLIENTS3 for which there are no linked records in [Item Transactions].

How can I include these extra records?

Please let me know if you need extra information.

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
Use a LEFT JOIN instead of INNER JOIN
0
LeighWardleAuthor Commented:
Thanks, Paul.

I substituted LEFT JOIN for INNER JOIN.

Access throws an error, "JOIN expression not supported.".  Ugh!
0
PortletPaulEE Topic AdvisorCommented:
mmmm, clearly Access does support left joins as you are already using one.

However, I would suggest using the clients table first, then left join the transactions.
This is my best guess without the ability to test:
TRANSFORM Count(Items.ItemCategory) AS CountOfItemCategory
SELECT CLIENTS3.ClientID
FROM ((CLIENTS3
LEFT JOIN [Item Transactions] ON CLIENTS3.ClientID = [Item Transactions].CustomerID)
LEFT JOIN Items  ON [Item Transactions].ItemID = Items.ItemID)
PIVOT Items.ItemCategory;

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

LeighWardleAuthor Commented:
Thanks, Paul, for your efforts.

Access gives this error: "Syntax error in TRANSFORM statement."

I've created an Access database for testing.

If the query outputs all the customers, the first row should have CustomerID=1.

Regards,
Leigh
0
LeighWardleAuthor Commented:
Sorry, the link for the Access database for testing is:
https://www.dropbox.com/s/j8mzhwutwq32wvq/Crosstab%20Query%20Test.zip?dl=0
0
PortletPaulEE Topic AdvisorCommented:
This worked for me:
TRANSFORM Count(CLIENTS3.ClientID) AS CountOfClientID
SELECT CLIENTS3.ClientID
FROM CLIENTS3 LEFT JOIN ([Item Transactions] LEFT JOIN Items ON [Item Transactions].ItemID = Items.ItemID) ON CLIENTS3.ClientID = [Item Transactions].CustomerID
GROUP BY CLIENTS3.ClientID
PIVOT Items.ItemCategory;

Open in new window


+ You need one row heading, one column heading and one value in the design viewaccess-xtab.PNGWhich produced:access-xtab-result.PNG
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Paul, you are a Legend!

Greetings from Blackburn/Melbourne.

Regards,
Leigh
0
PortletPaulEE Topic AdvisorCommented:
Many years since I was in Blackburn...

was a lad from Mt Evelyn/Lilydale travelling by train to school (Melb. High)
Blackburn was the station used by several (very attractive) girls

ah, memories

Now live in Williamstown and rarely use a train :)
0
LeighWardleAuthor Commented:
Life in Williamstown sounds good to me...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.