rubbernilly
Programmer
Hello again, all... I've been away from this forum for some time, but I am back with a question of my own. I don't know if I am out of practice, but I am just not seeing the best way to set this query up... function, sub-query, or inline computation. Here's the situation:
What I want to create is an incidents per 1000 vehicles (IPTV) query from the WarrantyInformation table, grouped on the PartNumber. Each PartNumber will have an entry that lists the total Claims and then the IPTV rate.
Currently, I sum the VehicleVolumes per VehicleCode (in a separate query called "VehicleVolumesSum") and then pull that value in by reference to the ModelCode from the WarrantyInformation table.
Here is the query that I have. It works, but has no date limitations:
So now I realize that if I want to limit the dates of the Claims made in the WarrantyInformation table, I will still be pulling in *all* of the Volume information for the VehicleCode, since that is not also limited.
To overcome this limitation, should I...
--use a VB function that expects arguments that would be fed by the same query parameters that would limit the dates
--use a subquery to get the right volume value I'm looking for
--use the same parameters on the VehicleVolumesSum query to equally limit the number of production months it totals for the Volume value
--generate this value by calculation in the query (is this even possible?)
Code:
[blue][b]Table:[/b] WarrantyInformation[/blue]
[b]Relevant Fields:[/b]
ClaimID (autonumber)
PartNumber
ModelCode
ProductionDate
[blue][b]Table:[/b] Vehicles[/blue]
[i](Slave to WarrantyInformation table on VehicleCode=ModelCode)[/i]
[b]Relevant Fields:[/b] VehicleCode
[blue][b]Table:[/b] VehicleVolumes[/blue]
[i](Slave to Vehicles table on VehicleCode field)[/i]
[b]Relevant Fields:[/b]
VehicleCode
ProdYear
ProdMonth
Volume
What I want to create is an incidents per 1000 vehicles (IPTV) query from the WarrantyInformation table, grouped on the PartNumber. Each PartNumber will have an entry that lists the total Claims and then the IPTV rate.
Currently, I sum the VehicleVolumes per VehicleCode (in a separate query called "VehicleVolumesSum") and then pull that value in by reference to the ModelCode from the WarrantyInformation table.
Here is the query that I have. It works, but has no date limitations:
Code:
SELECT WarrantyInformation.ProductID, Month([ProductionDate]) & "/" & Year([ProductionDate]) AS ProdMonth, WarrantyInformation.ModelCode, VehicleVolumesSum.Volume, Count(WarrantyInformation.ClaimID) AS Claims, [b]([Claims])/([Volume]/1000) AS IPTV[/b]
FROM WarrantyInformation INNER JOIN VehicleVolumesSum ON WarrantyInformation.ModelCode = VehicleVolumesSum.VehicleCode
GROUP BY WarrantyInformation.ProductID, Month([ProductionDate]) & "/" & Year([ProductionDate]), WarrantyInformation.ModelCode, VehicleVolumesSum.Volume;
So now I realize that if I want to limit the dates of the Claims made in the WarrantyInformation table, I will still be pulling in *all* of the Volume information for the VehicleCode, since that is not also limited.
To overcome this limitation, should I...
--use a VB function that expects arguments that would be fed by the same query parameters that would limit the dates
--use a subquery to get the right volume value I'm looking for
--use the same parameters on the VehicleVolumesSum query to equally limit the number of production months it totals for the Volume value
--generate this value by calculation in the query (is this even possible?)