April15Hater
Accountant
- Local time
- Yesterday, 21:53
- Joined
- Sep 12, 2008
- Messages
- 349
Hello everyone,
What I'm trying to do is get my query to return the ProductionID for matching ContractorFunctionID and ProductionUnit amounts. The ProductionUnits are assigned a ContractorFunctionID which describes what the units are for. There is a M2M relationship between tblContractorFunction and tblProductionInput, therefore there can be more than one ContractorFunctionID assigned to a particular Production ID.
I can get it to show the correct ProductionID when each of the subqueries are in solitude or there is an "or" between them rather than an "and". That would solve the problem except that if I substitute a ProductionUnit amount assigned to a different ProductionID yet the same ContractorFunctionID, it will return both ProductionID numbers when it should return nothing. Any ideas?
Here is my table structure:
tblProductionInputDetail
-ProductionInputDetailID
-ContractorFunctionID
-ProductionID
-ProductionUnits
tblProductionInput
-ProductionID
-CompleteDate
-ContractorID
-FunctionID
tblContractorFunction
-ContractorFunctionID
-FunctionID
-FunctionType
-FunctionCost
and my code...
Thanks!
Joe
What I'm trying to do is get my query to return the ProductionID for matching ContractorFunctionID and ProductionUnit amounts. The ProductionUnits are assigned a ContractorFunctionID which describes what the units are for. There is a M2M relationship between tblContractorFunction and tblProductionInput, therefore there can be more than one ContractorFunctionID assigned to a particular Production ID.
I can get it to show the correct ProductionID when each of the subqueries are in solitude or there is an "or" between them rather than an "and". That would solve the problem except that if I substitute a ProductionUnit amount assigned to a different ProductionID yet the same ContractorFunctionID, it will return both ProductionID numbers when it should return nothing. Any ideas?
Here is my table structure:
tblProductionInputDetail
-ProductionInputDetailID
-ContractorFunctionID
-ProductionID
-ProductionUnits
tblProductionInput
-ProductionID
-CompleteDate
-ContractorID
-FunctionID
tblContractorFunction
-ContractorFunctionID
-FunctionID
-FunctionType
-FunctionCost
and my code...
Code:
SELECT tblProductionInputDetail.ProductionID
FROM tblProductionInput INNER JOIN tblProductionInputDetail ON tblProductionInput.ProductionID = tblProductionInputDetail.ProductionID
WHERE FunctionID = 58 AND
(SELECT ProductionID
FROM tblProductionInputDetail as tblProductionInputDetail1
WHERE tblProductionInputDetail.ProductionID = tblProductionInputDetail1.ProductionID AND
tblProductionInputDetail.ProductionUnits = 830 AND
ContractorFunctionID = 157) AND
(SELECT ProductionID
FROM tblProductionInputDetail as tblProductionInputDetail1
WHERE tblProductionInputDetail.ProductionID = tblProductionInputDetail1.ProductionID AND
tblProductionInputDetail.ProductionUnits = 512 AND
ContractorFunctionID = 158)
Thanks!
Joe