HELP With Access Query

Posted on 2013-06-20
Last Modified: 2013-11-27
I am trying to create the following query in access 2010

FROM (Contact AS C INNER JOIN xmoWizardCancellation AS WC ON C.RecId = WC.xfContactRecID) INNER JOIN Activity AS A ON C.RecId = A.ParentLink_RecID
WHERE WC.xfStatus = 'Can'
AND WC.CreatedDateTime > 2013-06-18
AND (C.Owner = 'owner1'
OR C.Owner = 'owner2'
OR C.Owner = 'owner3')
GROUP By C.Owner

but keep getting the following error:
"Syntax Error (Missing Operator) in query expression 'COUNT (DISTINCT C.FullName)'

Any help will be appreciated
Question by:ahmzb1990
LVL 12

Expert Comment

ID: 39264838
I'm not sure that the "DISTINCT" and "GROUP BY" go together. Try

Select Count(C.FullName) as Total, ...

Expert Comment

ID: 39264857
You won't be able to do 'Count' on 'Distinct'. The Select needs to be changed as:
SELECT COUNT (C.FullName) AS Total, C.Owner

Author Comment

ID: 39264934
Thanks for your response guy however, without distinct it gives me duplicate values. Any other way of doing this?
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

LVL 12

Expert Comment

ID: 39264964
Not quite sure what you're after, but you may want to try

Select C.FullName, Count(*) as Total
From ...
Where ...
Group by C.FullName;

Accepted Solution

DOSLover earned 500 total points
ID: 39266226
Hi ahmzb1990,
Unlike SQL Server or Oracle, MS Access doesn't support DISTINCT with a Count. There is however a workaround. You need to get count in a subquery and then join that subquery with the main. Here is a helpful link:

: SELECT DISTINCT C2.FullNameCount as FullNameCount, C.Owner
 FROM ((Contact as C 
             INNER JOIN xmoWizardCancellation as WC ON C.RecId = Wc.cfContactRecId)
             INNER JOIN Activity as A ON A.ParentLink_RecId=C.RecId)
             INNER JOIN
             (SELECT C1.Owner, Count(C1.FullName) as FullNameCount
                  FROM (SELECT Distinct Owner, FullName from Contact) as C1
                 GROUP BY Owner) as C2 ON C2.Owner = C.Owner
Where  WC.xfStatus = 'Can'
AND WC.CreatedDateTime > 2013-06-18
AND (C.Owner = 'owner1'
OR C.Owner = 'owner2'
OR C.Owner = 'owner3')

Open in new window

LVL 45

Expert Comment

ID: 39267838
1. date/time literals need to be # delimited.
2. since this is Access, use mm/dd/yyyy formatted date literals
AND WC.CreatedDateTime > #06/18/2013#

Open in new window


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 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

13 Experts available now in Live!

Get 1:1 Help Now