Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get Last Inventory Record By Date
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Get Last Inventory Record By Date
Divers
Thread ID:
01405412
Message ID:
01405412
Vues:
88
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform