SELECT jobnumber, ProductName, ItemNumber from Product
inner join heading on Product.jobkeyid = heading.jobkeyid
WHERE DateDelivery = CAST( GETDATE() as date) AND heading.JobKeyID IN
(
SELECT tracking.ItemKeyID, MAX(StageID) stageid from Tracking
INNER join Production on Tracking.JobKeyID = Production.JobKeyID And production.ItemKeyID = Tracking.ItemKeyID
group by tracking.ItemKeyID
)
Main goal is to get the last scanned ID of each item using todays date
i have the date bit down but the last scanned is the issue and it needs to be in a sub query as it has multiple records