Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Make a qry output data by a field?

$
0
0
I have a database that tracks inspections. One of the options in the database allows me to forecast inspection requirements for each inspector. Another option allows me to pull up the forecast to see where all the inspectors are with their numbers.

The issue I am having is when multiple inspectors perform the same TypeEventCode the numbers get added together. So if Inspector 1 and 2 both perform 1 TypeEventCode the query will show that they both performed 2 and show that as a group we performed 4. I don't want this to happen. But can't seem to figure out how to make it stop.

The "InspectionsCW" block on the forecast query is part of a union query that pulls "SumofCountofReportID"

UNION Qry SQL is below:

Code:

SELECT FCastD, ForecastID, ForecastPeriod, MthlyDate, AssCat, AssCatName, TypeAssmentID, TypeAssmentAbbr, TypeEventCode, TECName, TECSC, TECSubCatName, TECC, TECCName, TypeWC, WorkCenter, GP, SQ, Flt, Sect, WC, InspID, QTYtoInspect, InspectionsCW, InspNumber, Inspector
FROM qryForecastMonthlyUnmatched

UNION SELECT FCastD, ForecastID, ForecastPeriod, MthlyDate, AssCat, AssCatName, TypeAssmentID, TypeAssmentAbbr, TypeEventCode, TECName, TECSC, TECSubCatName, TECC, TECCName, TypeWC, WorkCenter, GP, SQ, Flt, Sect, WC, InspID, QTYtoInspect, SumofCountofReportID, InspNumber, Inspector
FROM qryForecastMonthlymatched;

I need to make it so that the SumofCountofReportID shows the TypeEventCodes performed by each specific InspID instead of adding all the TypeEventCodes to all the InspID.

qryForecastMonthlyMatched:
Code:

SELECT qryForecastMonthly.FCastD, qryForecastMonthly.ForecastID, qryForecastMonthly.ForecastPeriod, qryForecastMonthly.MthlyDate, qryForecastMonthly.AssCat, qryForecastMonthly.AssCatName, qryForecastMonthly.TypeAssmentID, qryForecastMonthly.TypeAssmentAbbr, qryForecastMonthly.TypeEventCode, qryForecastMonthly.TECName, qryForecastMonthly.TECSC, qryForecastMonthly.TECSubCatName, qryForecastMonthly.TECC, qryForecastMonthly.TECCName, qryForecastMonthly.TypeWC, qryForecastMonthly.WorkCenter, qryForecastMonthly.GP, qryForecastMonthly.SQ, qryForecastMonthly.Flt, qryForecastMonthly.Sect, qryForecastMonthly.WC, qryForecastMonthly.InspID, qryForecastMonthly.QTYtoInspect, Sum(qryForecastMonthlyTotal.CountOfReportID) AS SumOfCountOfReportID, qryForecastMonthly.InspNumber, qryForecastMonthly.Inspector
FROM qryForecastMonthly LEFT JOIN qryForecastMonthlyTotal ON qryForecastMonthly.MthlyDate = qryForecastMonthlyTotal.MthlyDate
WHERE (((IIf([qryForecastMonthly]![TypeEventCode] Is Null,IIf([qryForecastMonthly]![TECSC] Is Null,IIf([qryForecastMonthly]![TECC] Is Null,True,[qryForecastMonthly]![TECC]=[qryForecastMonthlyTotal]![TECCategoryIdentifier]),[qryForecastMonthly]![TECSC]=[qryForecastMonthlyTotal]![TECSubCatIdentifier]),[qryForecastMonthly]![TypeEventCode]=[qryForecastMonthlyTotal]![TypeEventCode]))=True) AND ((IIf([qryForecastMonthly]![TypeAssmentID] Is Null,True,[qryForecastMonthly]![TypeAssmentID]=[qryForecastMonthlyTotal]![TypeAssment]))=True) AND ((IIf([qryForecastMonthly]![TypeWC]="1",[qryForecastMonthly]![GP]=[qryForecastMonthlyTotal]![GroupAssigned],IIf([qryForecastMonthly]![TypeWC]="2",[qryForecastMonthly]![SQ]=[qryForecastMonthlyTotal]![SquadronAssigned],IIf([qryForecastMonthly]![TypeWC]="3",[qryForecastMonthly]![Flt]=[qryForecastMonthlyTotal]![FlightAssigned],IIf([qryForecastMonthly]![TypeWC]="4",[qryForecastMonthly]![Sect]=[qryForecastMonthlyTotal]![SectionAssigned],IIf([qryForecastMonthly]![TypeWC]="5",[qryForecastMonthly]![WC]=[qryForecastMonthlyTotal]![WorkCenter],True))))))=True))
GROUP BY qryForecastMonthly.FCastD, qryForecastMonthly.ForecastID, qryForecastMonthly.ForecastPeriod, qryForecastMonthly.MthlyDate, qryForecastMonthly.AssCat, qryForecastMonthly.AssCatName, qryForecastMonthly.TypeAssmentID, qryForecastMonthly.TypeAssmentAbbr, qryForecastMonthly.TypeEventCode, qryForecastMonthly.TECName, qryForecastMonthly.TECSC, qryForecastMonthly.TECSubCatName, qryForecastMonthly.TECC, qryForecastMonthly.TECCName, qryForecastMonthly.TypeWC, qryForecastMonthly.WorkCenter, qryForecastMonthly.GP, qryForecastMonthly.SQ, qryForecastMonthly.Flt, qryForecastMonthly.Sect, qryForecastMonthly.WC, qryForecastMonthly.InspID, qryForecastMonthly.QTYtoInspect, qryForecastMonthly.InspNumber, qryForecastMonthly.Inspector;

qryForecastMonthlyUnmatched:
Code:

SELECT qryForecastMonthly.FCastD, qryForecastMonthly.ForecastID, qryForecastMonthly.ForecastPeriod, qryForecastMonthly.MthlyDate, qryForecastMonthly.AssCat, qryForecastMonthly.AssCatName, qryForecastMonthly.TypeAssmentID, qryForecastMonthly.TypeAssmentAbbr, qryForecastMonthly.TypeEventCode, qryForecastMonthly.TECName, qryForecastMonthly.TECSC, qryForecastMonthly.TECSubCatName, qryForecastMonthly.TECC, qryForecastMonthly.TECCName, qryForecastMonthly.TypeWC, qryForecastMonthly.WorkCenter, qryForecastMonthly.GP, qryForecastMonthly.SQ, qryForecastMonthly.Flt, qryForecastMonthly.Sect, qryForecastMonthly.WC, qryForecastMonthly.InspID, qryForecastMonthly.QTYtoInspect, 0 AS InspectionsCW, qryForecastMonthly.InspNumber, qryForecastMonthly.Inspector
FROM qryForecastMonthly LEFT JOIN qryForecastMonthlyMatched ON qryForecastMonthly.FCastD = qryForecastMonthlyMatched.FCastD
WHERE (((qryForecastMonthlyMatched.FCastD) Is Null));


Viewing all articles
Browse latest Browse all 13329

Trending Articles