work on problems with dss not reflecting last sales
This commit is contained in:
parent
47d77d3706
commit
fe67caf1af
@ -99,8 +99,8 @@ SELECT
|
||||
CASE WHEN rn_mrq = 1 THEN 'mrq' END AS f2,
|
||||
CASE WHEN rn_lvs = 1 THEN 'lvs' END AS f3,
|
||||
CASE WHEN rn_lvq = 1 THEN 'lvq' END AS f4,
|
||||
CASE WHEN rn_dss = 1 THEN 'dss' END AS f5,
|
||||
CASE WHEN rn_dsq = 1 THEN 'dsq' END AS f6
|
||||
CASE WHEN rn_dss = 1 AND version = 'Actual' THEN 'dss' END AS f5,
|
||||
CASE WHEN rn_dsq = 1 AND version = 'Quotes' THEN 'dsq' END AS f6
|
||||
INTO #flagged
|
||||
FROM ranked
|
||||
WHERE
|
||||
@ -108,8 +108,8 @@ WHERE
|
||||
OR rn_mrq = 1
|
||||
OR rn_lvs = 1
|
||||
OR rn_lvq = 1
|
||||
OR rn_dss = 1
|
||||
OR rn_dsq = 1;
|
||||
OR (rn_dss = 1 AND version = 'Actual')
|
||||
OR (rn_dsq = 1 AND version = 'Quotes');
|
||||
|
||||
CREATE NONCLUSTERED INDEX ix_flagged_lookup
|
||||
ON #flagged(customer, partgroup, dataseg, version, part, qty, price, odate, ordnum, quoten);
|
||||
@ -129,12 +129,15 @@ WITH exploded_flags AS (
|
||||
)
|
||||
--SELECT * FROM exploded_flags
|
||||
-- Step 3.2: Serialize each row into its JSON snippet
|
||||
-- Carry odate and version for deduplication in seg_pieces
|
||||
,serialized_flags AS (
|
||||
SELECT
|
||||
customer,
|
||||
partgroup,
|
||||
dataseg,
|
||||
flag,
|
||||
odate,
|
||||
version,
|
||||
CONCAT(
|
||||
'"', flag, '":',
|
||||
JSON_QUERY((
|
||||
@ -179,7 +182,8 @@ WITH exploded_flags AS (
|
||||
SELECT *,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY customer, partgroup, dataseg, flag
|
||||
ORDER BY odate DESC, version DESC -- prefer most recent, then prefer 'Actual' over 'Quotes'
|
||||
ORDER BY odate DESC,
|
||||
CASE WHEN version = 'Actual' THEN 1 ELSE 0 END DESC
|
||||
) AS rn
|
||||
FROM serialized_flags
|
||||
WHERE flag IN ('dss', 'dsq')
|
||||
|
Loading…
Reference in New Issue
Block a user