• 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

    Far away is close at hand in the images of elsewhere.
    Anon.