Solved

Access Query Continued

Posted on 2012-03-29
2
379 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…

705 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

20 Experts available now in Live!

Get 1:1 Help Now