Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pull Max Record In A Batch
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01415441
Message ID:
01415456
Views:
27
>>See
>>
>>Including an Aggregated Column's Related Values
>
>Yes, the ActionDate column.
select * from (SELECT i.*, p.PartNo, p.Description, l.Location, w.WarehouseCode, w.Caption AS Warehouse, w.WarehouseId, Row_Number() over (partition by p.PartNo, w.WarenhouseCode, i.Location order by ActionDate DESC) as RowNum
	FROM Inventory i
	JOIN Parts p ON p.PartId = i.PartId
	LEFT JOIN Locations l ON l.LocationId = i.LocationId
	LEFT JOIN Warehouses w ON w.WarehouseId = i.WarehouseId
	WHERE p.PartNo = @PartNo AND
		  (@SerialNo IS NULL OR i.SerialNo = @SerialNo) AND
		  w.WarehouseId = @WarehouseId AND
		  i.LocationId IS NOT NULL AND
		  l.RemoveFromInv = 0) where RowNum = 1
This is one of the possible solutions - may be the simplest one here.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform