Solved

Access Query Continued

Posted on 2012-03-29
2
386 Views
Last Modified: 2012-03-29
I have the following SQL that shows me all the the count on one side and the count on the other of a join. here is the fun part. there will always be a count from each table IF there is a count from [SeviceFailure]. in other words. for the year, month and carrier there can be a count from [ServiceFailure] and that would match exactly the match in tblSVF. However there can be a count of 0 in [ServiceFailre] and a count in tblSVF. I need to combine these two but not count them twice. so if there are is a count for one record of 2 in [ServiceFailures] there will also be a count for the same record of 2 from tblSVF. It seems like I need to compare the two counts. if they are the same then just count one of them. if there are more on the tblSVF than [ServiceFailures] then use the count from tblSVF. Confused yet? Help?

Here is the SQL

SELECT Year([SVFDATE]) AS LocalYear, MonthName(Month([SVFDate])) AS LocalMonth, tblSVF.CarrierCode, Count(tblSVF.CarrierCode) AS CountOfCarrierCode, Count(ServiceFailures.[SVORD#]) AS [CountOfSVORD#]
FROM tblSVF LEFT JOIN ServiceFailures ON tblSVF.CarrierCode = ServiceFailures.CARRIER
GROUP BY Year([SVFDATE]), MonthName(Month([SVFDate])), tblSVF.CarrierCode;

Here are the results

LocalYear      LocalMonth      CarrierCode      CountOfSVFORD      CountOfSVORD#
2012      March                 FILSPA                           1                              1
2012      March                GINSHE                           2                         0
2012      March                OTITEN                           4                              4
2012      March                QTRFRE                           4                              4
2012      March                STOSEA                           1                              1
0
Comment
Question by:JArndt42
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
JArndt42 earned 0 total points
ID: 37785066
I do believe I figured it out using an iif statement.  IIf([LC]=[AS],[AS],[LC]) AS CombinedCount
0
 
LVL 1

Author Comment

by:JArndt42
ID: 37785069
the entire sql statement is.

SELECT Year([SVFDATE]) AS LocalYear, MonthName(Month([SVFDate])) AS LocalMonth, tblSVF.CarrierCode, Count(tblSVF.SVFORD) AS LC, Count(ServiceFailures.[SVORD#]) AS [AS], IIf([LC]=[AS],[AS],[LC]) AS CombinedCount
FROM tblSVF LEFT JOIN ServiceFailures ON tblSVF.CarrierCode = ServiceFailures.CARRIER
GROUP BY Year([SVFDATE]), MonthName(Month([SVFDate])), tblSVF.CarrierCode;
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

785 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