David Burrows (5/7/2014)
Jack Corbett (5/6/2014)
Neither my nor David's code does exactly what you are looking for.Not that I would normally disagree with a master 🙂 but my second query produces the same results as yours 😀
Changed only to use new table def
;WITH cte (ID, Part, PartDescription, ReceiptDate, TimeBetween,MaxDate) AS (
SELECT ID, Part, PartDescription, ReceiptDate, TimeBetween,
MAX(ReceiptDate) OVER (PARTITION BY Part)
FROM Deliveries)
SELECT ID, Part, PartDescription, ReceiptDate, TimeBetween,MaxDate
FROM cte
WHERE ReceiptDate >= DATEADD(month,-6,MaxDate)
ORDER BY ID
Hehe, I only tested the first one you posted as a quick verification of what mine was doing.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question