Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / August 2006

Tip: Looking for answers? Try searching our database.

Sum Query Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ted - 11 Aug 2006 13:15 GMT
I have a query that works as I want except that I want total by
agent by state. It is returning total by agent by state by month.

My query:

SELECT DISTINCT
TOP 100 PERCENT dbo.tblAgents.AgentName,
dbo.tblProducers.State, dbo.tblAgents.AgentRep, COUNT
(dbo.tblMasterPolicy.PolicyNumber) AS [Policy Count],
dbo.tblCarrierProducts.CarrierID
FROM dbo.tblAgents INNER JOIN
dbo.tblReportData ON dbo.tblAgents.AgentID =
dbo.tblReportData.AgentID INNER JOIN
dbo.tblProducers ON dbo.tblReportData.ProducerID =
dbo.tblProducers.ProducerID INNER JOIN
dbo.tblMasterPolicy ON dbo.tblReportData.PolicyID =
dbo.tblMasterPolicy.PolicyID INNER JOIN
dbo.tblCarrierProducts ON dbo.tblReportData.ProductID
= dbo.tblCarrierProducts.ProductID
GROUP BY dbo.tblAgents.AgentName, dbo.tblProducers.State,
dbo.tblAgents.AgentRep, dbo.tblCarrierProducts.CarrierID,
dbo.tblMasterPolicy.ExportDate
HAVING (dbo.tblCarrierProducts.CarrierID LIKE 'fcic') AND
(dbo.tblMasterPolicy.ExportDate >= CONVERT(DATETIME, '2006-01-01
00:00:00', 102)) OR
(dbo.tblCarrierProducts.CarrierID LIKE 'nbic') AND
(dbo.tblMasterPolicy.ExportDate >= CONVERT(DATETIME, '2006-01-01
00:00:00', 102))
ORDER BY dbo.tblAgents.AgentName, dbo.tblProducers.State

Results sniped:

A. Philip Brown & Asscoiates MD 1 FCIC
A. Philip Brown & Asscoiates VA 3 FCIC
Accelerated Solutions MA 6 FCIC
Accelerated Solutions MA 1 FCIC
Advocate Solutions IL 160 FCIC
Advocate Solutions IL 172 FCIC
Advocate Solutions IL 173 FCIC
Advocate Solutions IL 47 FCIC
Advocate Solutions IL 152 FCIC
Advocate Solutions IL 71 FCIC
Advocate Solutions IL 185 FCIC
---SNIP----

As you can see, advocate solutions is listed more than once for IL
and I need it totaled for IL on one line for all the months.

I am sure that it is most likely something simple that I am
overlooking.

Thanks for the assistance.
Gary Walter - 11 Aug 2006 14:07 GMT
What happens if you drop ExportDate from GROUP BY
and include in a WHERE clause?

in fact, will your data produce same counts if

<snip>
dbo.tblCarrierProducts ON dbo.tblReportData.ProductID
= dbo.tblCarrierProducts.ProductID
WHERE
dbo.tblCarrierProducts.CarrierID IN ('FCIC', 'NBIC')
AND
dbo.tblMasterPolicy.ExportDate >= CONVERT(DATETIME, '2006-01-01
00:00:00', 102))
GROUP BY dbo.tblAgents.AgentName, dbo.tblProducers.State,
dbo.tblAgents.AgentRep, dbo.tblCarrierProducts.CarrierID
ORDER BY dbo.tblAgents.AgentName, dbo.tblProducers.State

> I have a query that works as I want except that I want total by
> agent by state. It is returning total by agent by state by month.
[quoted text clipped - 48 lines]
>
> Thanks for the assistance.
Ted - 15 Aug 2006 13:16 GMT
That did it. Thanks.

> What happens if you drop ExportDate from GROUP BY
> and include in a WHERE clause?
[quoted text clipped - 65 lines]
> >
> > Thanks for the assistance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.