Hello! Happy Holidays from the northland!
I have a rental database, in which I am trying to find the last location a piece of equipment was at and indicate in the inventory list whether it is in or out. But because equipment gets rented and returned often, my end date will not come up null. I first have a query that pulls the max start date:
Code:
SELECT DISTINCT Order.SerialNum, Max(Order.StartDate) AS MaxOfStartDate, Order.Equipment
FROM [Order]
GROUP BY Order.SerialNum, Order.Equipment;
And then another query using the first one to grab additional information (Account name, patient name etc).
Code:
SELECT Inventory.Equipment, Inventory.SerialNum, Account.AcctName, Order.PatientName, LastStartDate.MaxOfStartDate, Order.EndDate, IIf([maxofstartdate] Is Not Null And [enddate]=Null,"out","in") AS Status
FROM LastStartDate INNER JOIN (Account INNER JOIN ([Order] INNER JOIN Inventory ON Order.SerialNum = Inventory.SerialNum) ON Account.AcctNum = Order.AcctNum) ON LastStartDate.SerialNum = Inventory.SerialNum
GROUP BY Inventory.Equipment, Inventory.SerialNum, Account.AcctName, Order.PatientName, LastStartDate.MaxOfStartDate, Order.EndDate, IIf([maxofstartdate] Is Not Null And [enddate]=Null,"out","in");
What am I forgetting? (seems like more and more everyday!)