LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default tricky SQL problem using VBA Excel to read Access File

I'm having trouble with a somewhat complex SQL query I'm running from
Excel VBA to query an Access database. I'm trying to get as part of
the results the number of unique AccountNos served by each AuditorID
that meet all of the criteria, but instead the count is coming up as
the number of transactions (more than 1 per Account can be common).

The sql command is (broken up for readability here):

SELECT [Meas].[AuditorID], Count([HUacct].[AccountNo]) AS [Nunitlight],
Sum([Meas].[Qty]) AS [Nlight] FROM tblMeasureInstall Meas

INNER JOIN

(SELECT DISTINCTROW [TMI].[AccountNo]
FROM tblMeasureInstall TMI
WHERE ( [TMI].[InstallDate]<NULL AND ([TMI].[InstallDate] BETWEEN
#07/01/2005# AND #12/31/2005#) And ([TMI].[Canceled]<True) AND
([TMI].[MeasureID] in (62,63,77)) And ([TMI].[MeasureGroupID]=6) )
GROUP BY [TMI].[AccountNo] ) HUacct

ON [Meas].[AccountNo] = [HUacct].[AccountNo]

WHERE ( [Meas].[Canceled]<True AND [Meas].[MeasureGroupID]=3 ) GROUP
BY [AuditorID];

What I'm trying to get for the second column using
Count([HUacct].[AccountNo])
is a count of the number of unique AccountNos found in the table HUacct
(created by the nested second SELECT command) that are matched into
tblMeasureInstall. The HUacct table is grouped by AccountNo and has
DISTINCTROW, so it should be one record per AccountNo (which a separate
query confirms). But somehow after the join, my COUNT() comes up with
the number of qualifying transactions for all accounts of a given
AuditorID. The other results look OK. I've tried changing the JOIN
type from INNER to OUTER and RIGHT and LEFT and haven't gotten
anywhere. I'd appreciate any SQL-guru who could help.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When opening Excel - get Access (Read-Only) file and error DeltaDagger Setting up and Configuration of Excel 1 October 31st 06 10:22 AM
i cannot open excel file error Cannot access read-only document me Lenda. Excel Worksheet Functions 1 March 14th 05 06:15 PM
Network access to file - read only property AL Excel Discussion (Misc queries) 1 December 2nd 04 01:22 AM
Use ADO in VB to read excel file problem ong Excel Programming 5 September 6th 04 02:33 PM
tricky Excel/VBA/Access needed Doug Shannon Excel Programming 3 June 22nd 04 04:18 PM


All times are GMT +1. The time now is 01:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"