Distinguishing Different Occasions
Feb 4, 2006I have a database that keeps track of equipment that is loaned out and returned. Each piece of equipment has an EquipmentID and the same piece of equipment maybe loaned out and then returned and loan out again etc.
I am trying to create a query which shows what equipment is on loan and what equipment is in stock. It works fine except where the equipment has been loaned out and then returned and then loaned out again. Hence at that stage it is now on loan. When I run my query it brings up all occasions where it has been loaned and hence it may say that it is "on loan" and also "in stock"
This is the sql of the query
SELECT [Equipment Inventory].[OT Equipment type], [Equipment Inventory].IDTagNumber, [Equipment Inventory].[PT Equipment type], IIf((([Loan details].[Returned] Is Null) Or ([Loan details].[Returned]=Yes)),"In Stock","On Loan") AS Location
FROM [Equipment Inventory] LEFT JOIN [Loan details] ON [Equipment Inventory].EquipmentID = [Loan details].EquipmentID
WHERE ((([Equipment Inventory].WriteOffDate) Is Null) AND (([Loan details].EquipmentID) Is Null)) OR ((([Equipment Inventory].WriteOffDate) Is Null)) OR ((([Equipment Inventory].WriteOffDate) Is Null) AND (([Loan details].Returned)=No)) OR (((IIf((([Loan details].[Returned] Is Null) Or ([Loan details].[Returned]=Yes)),"In Stock","On Loan"))="Finding Last return date"))
ORDER BY [Equipment Inventory].[OT Equipment type], [Equipment Inventory].[PT Equipment type];
Is anyone able to assist?