Solved

HELP With Access Query

Posted on 2013-06-20
6
181 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
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

896 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

17 Experts available now in Live!

Get 1:1 Help Now