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
Divers
Thread ID:
01405412
Message ID:
01405413
Vues:
48
IIRC from your previous posts, it should be
...
		  i.ActionDate =
			(SELECT MAX(i2.ActionDate)
				FROM Inventory i2
				WHERE i2.WarehouseId = i.WarehouseId 
						AND i2.PartId = i.PartId
						AND i2.SerialNo = i.SerialNo )
>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
>
>
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform