So I'm using a fairly complex query with a couple of sub-queries as expressions:
Now, access doesn't seem to have a problem with this, except when it comes to calculating the last line ([Qty In]-([Qty Processed]+[Qty Taken]) AS [Qty Remaining]).
although [Qty Processed] is previously displayed correctly, when performing this calculation Access decided it should be multiplied by 10 before being added to [Qty Taken], resulting in a massively negative [Qty Remaining].
changing the line to:
[Qty In]-[Qty Processed]-[Qty Taken]
all of a sudden seemed to sort things out and [Qty Remaining] is now displayed correctly.
Can anyone explain what the hell is going on here, as I spent about half an hour trying to debug the sub-queries before figuring this out... & want to avoid similar mistakes in the future...
cheers,
Bogzla
Code:
SELECT tblPPIn.BatchID,
tblPPIn.Qty AS [Qty In],
IIf(IsNull((SELECT Sum(tblPPProcessed.QtyProcessed) AS SumOfQty1 FROM tblPPProcessed WHERE (((tblPPProcessed.BatchID)=(tblPPIn.BatchID)));)),'0',(SELECT Sum(tblPPProcessed.QtyProcessed) AS SumOfQty1 FROM tblPPProcessed WHERE (((tblPPProcessed.BatchID)=(tblPPIn.BatchID)));)) AS [Qty Processed],
IIf(IsNull((SELECT Sum(tblPPOut.Qty) AS SumOfQty FROM tblPPOut WHERE (((tblPPOut.IQCPass)="UNINSPECTED") and ((tblPPOut.BatchID)=(tblPPin.BatchID)));)),'0',(SELECT Sum(tblPPOut.Qty) AS SumOfQty FROM tblPPOut WHERE (((tblPPOut.IQCPass)="UNINSPECTED") and ((tblPPOut.BatchID)=(tblPPin.BatchID)));)) AS [Qty Taken],
[Qty In]-([Qty Processed]+[Qty Taken]) AS [Qty Remaining]
FROM tblPPIn;
Now, access doesn't seem to have a problem with this, except when it comes to calculating the last line ([Qty In]-([Qty Processed]+[Qty Taken]) AS [Qty Remaining]).
although [Qty Processed] is previously displayed correctly, when performing this calculation Access decided it should be multiplied by 10 before being added to [Qty Taken], resulting in a massively negative [Qty Remaining].
changing the line to:
[Qty In]-[Qty Processed]-[Qty Taken]
all of a sudden seemed to sort things out and [Qty Remaining] is now displayed correctly.
Can anyone explain what the hell is going on here, as I spent about half an hour trying to debug the sub-queries before figuring this out... & want to avoid similar mistakes in the future...
cheers,
Bogzla