Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HELP With Access Query

Posted on 2013-06-20
6
Medium Priority
?
219 Views
Last Modified: 2013-11-27
I am trying to create the following query in access 2010

SELECT COUNT (DISTINCT C.FullName) AS Total, C.Owner
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
0
Comment
Question by:ahmzb1990
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

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

Select Count(C.FullName) as Total, ...
0
 
LVL 5

Expert Comment

by:DOSLover
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
....
.....
0
 

Author Comment

by:ahmzb1990
ID: 39264934
Thanks for your response guy however, without distinct it gives me duplicate values. Any other way of doing this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:pdebaets
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;
0
 
LVL 5

Accepted Solution

by:
DOSLover earned 2000 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: http://blogs.office.com/b/microsoft-access/archive/2007/09/19/writing-a-count-distinct-query-in-access.aspx

: 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

0
 
LVL 46

Expert Comment

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

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

604 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