Compare commits
No commits in common. "d79feebaa57fe65f3fde6eda7a185255ab90d22f" and "a0c5482f6c5e05683d4f5d2979c72123b278e865" have entirely different histories.
d79feebaa5
...
a0c5482f6c
@ -1,18 +1,33 @@
|
||||
-- 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
|
||||
baseline AS (
|
||||
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 (
|
||||
SELECT
|
||||
-----------documents-------------
|
||||
null::int "ddord#"
|
||||
@ -122,15 +137,15 @@ baseline AS (
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'b23' "version"
|
||||
,'15mo' "version"
|
||||
,'actuals' iter
|
||||
FROM
|
||||
rlarp.osm o
|
||||
--snap the ship dates of the historic fiscal period
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
--get the shipping season for open orders based on the snapped date
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
(
|
||||
@ -280,23 +295,19 @@ baseline 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
|
||||
,'b23' "version"
|
||||
,'actuals' "version"
|
||||
,'actuals_plug' iter
|
||||
FROM
|
||||
rlarp.osm o
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
LEFT OUTER JOIN 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'
|
||||
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'
|
||||
--)
|
||||
------exclude actuals for now and use forecast to get the plug for the rest of the year
|
||||
AND version = 'ACTUALS'
|
||||
GROUP BY
|
||||
o.fspr
|
||||
@ -432,13 +443,13 @@ baseline AS (
|
||||
-----when null, greatest/least is just going to act like coalesce
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||
,ss.ssyr sseas
|
||||
,'b23' "version"
|
||||
,'actuals' "version"
|
||||
,'forecast_plug' iter
|
||||
FROM
|
||||
rlarp.osmp o
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
LEFT OUTER JOIN gld ON
|
||||
gld.fspr = o.fspr
|
||||
LEFT OUTER JOIN rlarp.gld ss ON
|
||||
LEFT OUTER JOIN gld ss ON
|
||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||
WHERE
|
||||
false
|
||||
@ -468,7 +479,6 @@ baseline AS (
|
||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||
,ss.ssyr
|
||||
)
|
||||
----------increment the baseline selection---------------------
|
||||
,incr AS (
|
||||
SELECT
|
||||
o."ddord#"
|
||||
@ -579,8 +589,8 @@ SELECT
|
||||
,'copy' iter
|
||||
FROM
|
||||
baseline o
|
||||
LEFT OUTER JOIN rlarp.gld ON
|
||||
(o.sdate + interval '1 year') BETWEEN gld.sdat and gld.edat
|
||||
LEFT OUTER JOIN gld ON
|
||||
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
||||
WHERE
|
||||
o.odate + interval '1 year' >= '2023-06-01'
|
||||
)
|
||||
|
@ -127,7 +127,7 @@ SELECT
|
||||
FROM
|
||||
rlarp.osm_pool
|
||||
WHERE
|
||||
substring(iter,1,7) <> 'actuals';
|
||||
version <> 'actuals';
|
||||
|
||||
-------need to set item master values before other things-----------
|
||||
UPDATE
|
||||
|
Loading…
Reference in New Issue
Block a user