Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Last Inventory Record By Date
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Get Last Inventory Record By Date
Miscellaneous
Thread ID:
01405412
Message ID:
01405412
Views:
87
I have a datetime column called ActionDate on an inventory record. Each time a change is made a new record is inserted so that
I will always have a history.

I want to get back the last inventory record for a warehouse for a part #. Here's what I have so far. I'm getting back all records:
SELECT i.InventoryId, i.LocationId, i.LocationInfo, l.Location, p.PartNo, p.Description, i.SerialNo
	FROM Inventory i
	JOIN Locations l ON l.LocationId = i.LocationId
	JOIN Parts p ON p.PartId = i.PartId
	WHERE i.WarehouseId = @WarehouseId AND
		  p.PartNo = @PartNo AND
		  (@SerialNo IS NULL OR i.SerialNo = @SerialNo) AND
		  i.ActionDate =
			(SELECT MAX(i2.ActionDate)
				FROM Inventory i2
				WHERE i2.InventoryId = i.InventoryId
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform