Please explain how both your actual business works (don't use any database jagon, explain what you actually do as if we were elementary students and you were a career day presenter) and then explain your thinking about having a table for products (feel free to jargon out).
This is all about how granularly you need to track your sugar. It comes in a lot, but does it need to be dispersed to individuals as such? Do you need to know Sally got 4 lbs from lot 15 and 1 lb from lot 23? Or do you just car that Sally got 5 lbs of sugar?
I mean, once you accept a lot of sugar into inventory do you care if all your sugar gets dumped together in one big vat and then dispersed as needed, or do you need to keep each lot of sugar seperate all the way up to dispersing it?
1. A description of what your company does without using any database jargon. Don't tell me about tables or queries or anything about your database. Just tell me what your company does.
2. Tell me what role this database will fill within that business. Here you are free to use jargon, but I advise against it.
First, you don't need tables with only 1 real field of data (autonumbers don't count as real data). So that means as they stand now, you can eliminate tblFactors, tblMfr and tblTransactionType
Also, to sort out your inventory transactions, you should do this in a table that stands between tblOrders and tblLots, I just think the fields you have in tblProducts is incorrect, is poorly named and doesn't allow credits to inventory. Attached is a screenshot of what I believe should be the crux of your tables/relationships.
I believe you shoudl have tblTransactions. This will allow you to both add and subtract from inventory. Let me know if you have any questions.
I've attached my current relationship layout, and what I adjusted it from.
And which is which? And why even include the old bad one?
So 5809 is the one.
That looks good. A few nitpicks:
[Date] is a reserved word. Change that field name to reflect what date it represents-- [OrderDate].
TblTransactionTypes should have a field to denote if that type of transaction is a credit or a debit. In my structure image I named that TransTypeAction. Then for the values I would make it either -1 (removed from inventory) and 1 (added to inventory). Then I would multiply that value by [TransactionAmount] to determine how it actually affected inventory.
Also, I used MedRec instead of PatientID because MedRec should be unique to a specific Patient. When I have a unique value like that external to my system I usually use it, instead of using an autonumber primary key (kind of like if I had SSN I would use it, or if I had a Vehicle Serial number I would use it).
SELECT FactorsID, SUM(OrderAmount * TransTypeAction) AS Inventory
FROM tblOrders
INNER JOIN tblTransactionTypes ON ID_TransactionType = TransactionTypeID
GROUP BY FactorsID
If you had my TransTypeAction field in tblTransTypes, this SQL would give you inventory:
Code:SELECT FactorsID, SUM(OrderAmount * TransTypeAction) AS Inventory FROM tblOrders INNER JOIN tblTransactionTypes ON ID_TransactionType = TransactionTypeID GROUP BY FactorsID
That tells you the inventory of any Lot.
SELECT FactorsID, SUM(OrderAmount * TransTypeAction) AS Inventory
FROM tblOrders
INNER JOIN tblTransactionTypes ON ID_TransactionType = TransactionTypesID
GROUP BY FactorsID;
SELECT tORD.FactorsID, SUM(tORD.OrderAmount * tTRA.TransactionTypesAction) AS Inventory
FROM tblOrders AS tORD
INNER JOIN tblTransactionTypes AS tTRA ON tTRA.TransactionTypesID=tORD.ID_TransactionTypes
GROUP BY FactorsID;