change version to b23
This commit is contained in:
parent
a0c5482f6c
commit
0ae9f604c1
@ -1,33 +1,18 @@
|
||||
-- Connection: usmidsap01.ubm
|
||||
--\timing
|
||||
|
||||
/*----------------------------------------------------------------------------------------
|
||||
1. copy existing actuals for the current season (which is incomplete)
|
||||
* for example 6/1/22 -> 3/7/23
|
||||
2. fill out a full year of history by going back 2 years to get 3/8/22 -> 5/31/22
|
||||
3. stack the results of 1 & 2 and increment all rows by 1 year
|
||||
*/----------------------------------------------------------------------------------------
|
||||
|
||||
TRUNCATE TABLE rlarp.osmf;
|
||||
|
||||
INSERT INTO rlarp.osmf
|
||||
WITH
|
||||
gld AS (
|
||||
SELECT
|
||||
N1COMP COMP
|
||||
,N1CCYY FSYR
|
||||
,KPMAXP PERDS
|
||||
,N1FSPP PERD
|
||||
,to_char(N1FSYP,'FM0000') FSPR
|
||||
,N1SD01 SDAT
|
||||
,N1ED01 EDAT
|
||||
,to_char(N1ED01,'yymm') CAPR
|
||||
,N1ED01 - N1SD01 +1 NDAYS
|
||||
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
||||
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
|
||||
FROM
|
||||
LGDAT.GLDATREF
|
||||
INNER JOIN LGDAT.GLDATE ON
|
||||
KPCOMP = N1COMP AND
|
||||
KPCCYY = N1CCYY
|
||||
WHERE
|
||||
N1COMP = 93
|
||||
--AND DIGITS(N1FSYP) = '1901'
|
||||
)
|
||||
--SELECT * FROM gld
|
||||
,baseline AS (
|
||||
baseline AS (
|
||||
SELECT
|
||||
-----------documents-------------
|
||||
null::int "ddord#"
|
||||
@ -137,15 +122,15 @@ gld AS (
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'15mo' "version"
|
||||
,'b23' "version"
|
||||
,'actuals' iter
|
||||
FROM
|
||||
rlarp.osm o
|
||||
--snap the ship dates of the historic fiscal period
|
||||
LEFT OUTER JOIN gld ON
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
gld.fspr = o.fspr
|
||||
--get the shipping season for open orders based on the snapped date
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
(
|
||||
@ -295,19 +280,23 @@ gld AS (
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'b23' "version"
|
||||
,'actuals_plug' iter
|
||||
FROM
|
||||
rlarp.osm o
|
||||
LEFT OUTER JOIN gld ON
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
o.odate BETWEEN '2022-03-01' AND '2022-05-31'
|
||||
AND fs_line = '41010'
|
||||
AND calc_status <> 'CANCELED'
|
||||
------exclude actuals for now and use forecast to get the plug for the rest of the year
|
||||
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
||||
--OR (
|
||||
-- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000')
|
||||
-- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31'
|
||||
--)
|
||||
AND version = 'ACTUALS'
|
||||
GROUP BY
|
||||
o.fspr
|
||||
@ -443,13 +432,13 @@ gld AS (
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'actuals' "version"
|
||||
,'b23' "version"
|
||||
,'forecast_plug' iter
|
||||
FROM
|
||||
rlarp.osmp o
|
||||
LEFT OUTER JOIN gld ON
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
false
|
||||
@ -479,6 +468,7 @@ gld AS (
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
)
|
||||
----------increment the baseline selection---------------------
|
||||
,incr AS (
|
||||
SELECT
|
||||
o."ddord#"
|
||||
@ -589,8 +579,8 @@ SELECT
|
||||
,'copy' iter
|
||||
FROM
|
||||
baseline o
|
||||
LEFT OUTER JOIN gld ON
|
||||
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
(o.sdate + interval '1 year') BETWEEN gld.sdat and gld.edat
|
||||
WHERE
|
||||
o.odate + interval '1 year' >= '2023-06-01'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user