Hello Experts
I have created "Test" a table with 4 fields
ID JobNo ProductID QtyRequired
This table contain the following data
ID JobNo ProductID QtyRequired
1 1 4 2
2 1 4 3
3 1 3 7
4 3 2 2
Now i have only JobNo 1 to filter record in a table now i want to calculate the QtyRequired where ProductID = ProductID;
EG:
var
QtyRequiredSum : Integer;
QtyReqiredSum += Test.QtyRequired; // but only calculate those qtyRequied where producId = productID like for the first two record.
Thanks .
Looks like you want to group the qty required by Product ID, if so loop the original table and add the records in a temporary table and the logic should be if you find the product id in the temporary table update qty required if not insert the record.
// Warning - un-tested code ahead :-)
QtyRequiredSum = 0;
Test.SETRANGE(JobNo, 1);
IF Test.FINDFIRST() THEN BEGIN
Test2.SETRANGE(JobNo, Test.JobNo);
Test2.SETRANGE(ProductID, Test.ProductID);
Test2.CALCSUMS(QtyRequired);
QtyRequiredSum := Test2.QtyRequired;
END;
Note: This assumes you only want the result for the first row (combination of JobNos and ProductIDs) - i assume this because you only have one QtyRequiredSum...
If you need all you should create a loop and make logic to so you don't calculate already calculated combinations of JobNos/ProductIDs…
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156