Solved

HELP With Access Query

Posted on 2013-06-20
6
202 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 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: 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 45

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating a Temp Table in MS Access 5 48
Saving data on a subform when I close the form 12 33
Parameter Query 33 52
MS Access populate a field based on 2 other form fields 14 36
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

730 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