From b62f2275d6f35678fac9ba97cf3d8a5b2cfa4a9e Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 2 Oct 2025 14:00:43 -0400 Subject: [PATCH] partition by data source so that row number will start with 1 inside of actuals or quotes --- rebuild/rebuild_lastprice.ms.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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