best way to Calculate Qty on Hand in Database?

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

best way to Calculate Qty on Hand in Database?

Post by siamandm »

Hello All,
I have tired to calculate the quantity on hand using query as below, but someone told me this way works for small business and small number, it will slow down when you have a large amount of orders!, could you please advice better way?
Screenshot 2024-04-22 094456.png
and
Screenshot 2024-04-22 094902.png
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: best way to Calculate Qty on Hand in Database?

Post by HansV »

How many records do you expect? On modern PCs, Access is quite capable of calculating the stock on hand on the fly for thousands of records. It might become a problem if you have hundreds of thousands or millions of records.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

Re: best way to Calculate Qty on Hand in Database?

Post by siamandm »

Thank you for the reply,
so you mean for a medium business that having 10K records 6 or less in a month will not have an issue they way i posted?
Regards

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: best way to Calculate Qty on Hand in Database?

Post by HansV »

In my experience, they shouldn't have problems.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

Re: best way to Calculate Qty on Hand in Database?

Post by siamandm »

Thank you very much

User avatar
Gasman
2StarLounger
Posts: 113
Joined: 22 Feb 2022, 09:04

Re: best way to Calculate Qty on Hand in Database?

Post by Gasman »

I would expect large companies like Amazon, use the same method?
Perhaps ask your someone how he would do it, and keep the quantity on hand accurate all the time? :evilgrin:
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: best way to Calculate Qty on Hand in Database?

Post by SpeakEasy »

Gasman wrote:
22 Apr 2024, 07:44
I would expect large companies like Amazon, use the same method?
I wouldn't expect them to be using Access ...

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

Re: best way to Calculate Qty on Hand in Database?

Post by siamandm »

another approach suggested by a friend, is adding QtyOnHand to table ProductT, and use an update query to deduct number from QtyOnHand
but not sure how this method is more effective or not
Screenshot 2024-04-22 120320.png
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: best way to Calculate Qty on Hand in Database?

Post by HansV »

That method is often used if the number of records is expected to be very large. Storing the quantity on hand is more efficient than calculating it each time in that situation.
But there is a small risk that the stored quantity will become inaccurate over time, for example if a delivery or order is cancelled.
So if you do this, it is advisable to check the stock against the values stored in the database periodically, for example once or twice a year, and correct the values in the database if necessary.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

Re: best way to Calculate Qty on Hand in Database?

Post by siamandm »

can we add a button to put Quantity back to the Junction table PurchaseDetailsT ?

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: best way to Calculate Qty on Hand in Database?

Post by HansV »

Sorry, I don't understand. From where would you want to place Quantity into PurchaseDetailT? And why?
Best wishes,
Hans

User avatar
Gasman
2StarLounger
Posts: 113
Joined: 22 Feb 2022, 09:04

Re: best way to Calculate Qty on Hand in Database?

Post by Gasman »

SpeakEasy wrote:
22 Apr 2024, 08:38
Gasman wrote:
22 Apr 2024, 07:44
I would expect large companies like Amazon, use the same method?
I wouldn't expect them to be using Access ...
Nor would I, but the logic would be the same?
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

siamandm
BronzeLounger
Posts: 1246
Joined: 01 May 2016, 09:58

Re: best way to Calculate Qty on Hand in Database?

Post by siamandm »

HansV wrote:
23 Apr 2024, 14:23
Sorry, I don't understand. From where would you want to place Quantity into PurchaseDetailT? And why?
What I mean is when we an order, the quantity in the the PurchaseDetailsT table decrease, so in case one of the orders has been canceled for any reason we have to increase back the quantity in the PurchaseDetailsT table using a Cancel Order button and removed from the orderDetailsT table as well