name the column after incrementing, put variables in single quotes, move the final filter to another layer
This commit is contained in:
parent
4ed3f11bd8
commit
39a8454b0e
@ -77,7 +77,7 @@ SELECT
|
|||||||
ELSE
|
ELSE
|
||||||
--use the date key but increment by the target interval
|
--use the date key but increment by the target interval
|
||||||
--this assumes that the primary key for the func is a date, but it has to be or it wont join anyways
|
--this assumes that the primary key for the func is a date, but it has to be or it wont join anyways
|
||||||
'o.'||fkey||' + interval '||format('%L',_interval)
|
'o.'||fkey||' + interval '||format('%L',_interval) ||' AS '||fkey
|
||||||
END
|
END
|
||||||
ELSE
|
ELSE
|
||||||
'o.'||format('%I',cname)
|
'o.'||format('%I',cname)
|
||||||
@ -107,11 +107,11 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
$$||_order_date||$$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date]
|
$$||_order_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
OR ($$||_order_status||$$ IN ([app_openstatus_code]) and $$||_order_date||$$ <= [app_openorder_cutoff])
|
OR ($$||_order_status||$$ IN (app_openstatus_code) and $$||_order_date||$$ <= 'app_openorder_cutoff'::date)
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR ($$||_ship_date||$$ BETWEEN [app_baseline_from_date] AND [app_baseline_to_date])
|
OR ($$||_ship_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
|
||||||
)
|
)
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$$::text
|
$$::text
|
||||||
@ -132,7 +132,7 @@ $$
|
|||||||
FROM
|
FROM
|
||||||
fc.live o$$||E'\n'||_perd_joins||$$
|
fc.live o$$||E'\n'||_perd_joins||$$
|
||||||
WHERE
|
WHERE
|
||||||
$$||_order_date||$$ BETWEEN [app_plug_fromdate] AND [app_plug_todate]
|
$$||_order_date||$$ BETWEEN 'app_plug_fromdate'::date AND 'app_plug_todate'::date
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$$
|
$$
|
||||||
INTO
|
INTO
|
||||||
@ -141,8 +141,9 @@ INTO
|
|||||||
------------------------------copy a full year and increment by 1 year for the baseline-------------------------
|
------------------------------copy a full year and increment by 1 year for the baseline-------------------------
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
$$INSERT INTO
|
--$$INSERT INTO
|
||||||
fc.live
|
-- fc.live
|
||||||
|
$$,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
$$||_clist_inc||
|
$$||_clist_inc||
|
||||||
$$
|
$$
|
||||||
@ -150,9 +151,16 @@ SELECT
|
|||||||
,'baseline' iter
|
,'baseline' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o$$||E'\n'||_perd_joins||$$
|
baseline o$$||E'\n'||_perd_joins||$$
|
||||||
|
)
|
||||||
|
INSERT INTO
|
||||||
|
fc.live
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
incr i
|
||||||
WHERE
|
WHERE
|
||||||
$$||_order_date||' >= [app_first_forecast_date]'||$$
|
i.$$||_order_date||$$ >= 'app_first_forecast_date'::date$$||$$
|
||||||
OR $$||_ship_date||' >= [app_first_forecast_date]'
|
OR i.$$||_ship_date||$$ >= 'app_first_forecast_date'::date$$
|
||||||
--any orders in the forecast period, or any sales in the forecast period (from open orders)
|
--any orders in the forecast period, or any sales in the forecast period (from open orders)
|
||||||
INTO
|
INTO
|
||||||
_baseline;
|
_baseline;
|
||||||
|
Loading…
Reference in New Issue
Block a user