Solved

Access Query Continued

Posted on 2012-03-29
2
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GA Ribbon creator 9 63
Queries: Select, then Append, then Delete 8 41
updating subform when combobox is updated 4 17
SqlServer amend PK column 5 11
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
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 views 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 Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

738 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