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