diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index ddc41e7..9a29b4f 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -13,6 +13,7 @@ target AS (select $$replace_request$$::json def) ,to_char(N1FSYP,'FM0000') FSPR ,N1SD01 SDAT ,N1ED01 EDAT + ,daterange(n1sd01, n1ed01) drange ,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 @@ -251,11 +252,11 @@ SELECT JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true CROSS JOIN mxm LEFT OUTER JOIN gld od ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat + od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom) LEFT OUTER JOIN gld rd ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat + od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag) LEFT OUTER JOIN gld sd ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat + od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag) ) --SELECT * FROM basemix ,log AS ( @@ -336,7 +337,7 @@ SELECT FROM basemix b CROSS JOIN log - LEFT OUTER JOIN rlarp.itemm i ON + LEFT OUTER JOIN rlarp.itemmv i ON i.item = b.part LEFT OUTER JOIN SEG ON SEG.GLEC = i.glec