diff --git a/rebuild/rebuild_lastprice.ms.sql b/rebuild/rebuild_lastprice.ms.sql index 98b05ef..8dc5302 100644 --- a/rebuild/rebuild_lastprice.ms.sql +++ b/rebuild/rebuild_lastprice.ms.sql @@ -62,21 +62,21 @@ BEGIN -- Most recent sale (Actuals only) ,CASE WHEN b.version = 'Actual' THEN ROW_NUMBER() OVER ( - PARTITION BY b.customer, b.partgroup + PARTITION BY b.customer, b.partgroup, b.version ORDER BY b.odate DESC ) END AS rn_mrs -- Most recent quote (Quotes only) ,CASE WHEN b.version = 'Quotes' THEN ROW_NUMBER() OVER ( - PARTITION BY b.customer, b.partgroup + PARTITION BY b.customer, b.partgroup, b.version ORDER BY b.odate DESC ) END AS rn_mrq -- Largest volume sale (Actuals only; last 12 months prioritized) ,CASE WHEN b.version = 'Actual' THEN ROW_NUMBER() OVER ( - PARTITION BY b.customer, b.partgroup + PARTITION BY b.customer, b.partgroup, b.version ORDER BY CASE WHEN b.version = 'Actual' AND b.odate >= DATEADD(YEAR, -1, GETDATE()) THEN 1 ELSE 0 END DESC, b.qty DESC @@ -85,7 +85,7 @@ BEGIN -- Largest volume quote (Quotes only; last 12 months prioritized) ,CASE WHEN b.version = 'Quotes' THEN ROW_NUMBER() OVER ( - PARTITION BY b.customer, b.partgroup + PARTITION BY b.customer, b.partgroup, b.version ORDER BY CASE WHEN b.version = 'Quotes' AND b.odate >= DATEADD(YEAR, -1, GETDATE()) THEN 1 ELSE 0 END DESC, b.qty DESC