Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access Query Continued

Posted on 2012-03-29
2
Medium Priority
?
395 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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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