Compare commits

...

2 Commits

2 changed files with 28 additions and 7 deletions

View File

@ -8,16 +8,10 @@ baseline AS (
,'actuals' iter
FROM
rlarp.osm_dev o
--snap the ship dates of the historic fiscal period
LEFT OUTER JOIN gld ON
gld.fspr = o.fspr
--get the shipping season for open orders based on the snapped date
LEFT OUTER JOIN gld ss ON
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
WHERE
(
--base period orders booked....
[target_odate] BETWEEN [target_odate_from] AND [target_odate_to]
[order_field_name] BETWEEN [target_odate_from] AND [target_odate_to]
--...or any open orders currently booked before cutoff....
OR ([status_flag] IN ([status_list]) and [target_date] <= [target_date_from])
--...or anything that shipped in that period

27
sql/col_interval.sql Normal file
View File

@ -0,0 +1,27 @@
DO
$$
DECLARE
clist text;
BEGIN
-------------------------------build a column list----------------------------------------
SELECT
string_agg(
format('%I',cname) || CASE WHEN func IN ('odate','sdate') THEN ' + interval ''1 year''' ELSE '' END,E'\n,' ORDER BY opos ASC)
INTO
clist
FROM
fc.target_meta
WHERE
func NOT IN ('version');
RAISE NOTICE 'build list: %',clist;
CREATE TEMP TABLE sql(t text);
INSERT INTO sql SELECT clist;
END
$$;
select * from sql;