diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 9aea189..807057b 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -72,6 +72,7 @@ target AS (select $$replace_request$$::json def) ,REPC AS ( SELECT LTRIM(RTRIM(C.A9)) RCODE + ,c.a30 rname ,LTRIM(RTRIM(C.A9)) || ' - ' || C.A30 REPP ,COALESCE(Q.DIR,'Other') DIRECTOR FROM @@ -271,9 +272,9 @@ SELECT ,bc.bvterm terms ,b.bill_cust_descr ,b.ship_cust_descr - ,(SELECT rcode FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') dsm + ,(SELECT max(rcode) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') dsm ,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr - ,(SELECT director FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') director + ,(SELECT max(director) FROM repc WHERE rname = log.doc->'scenario'->>'quota_rep_descr') director ,CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END billto_group ,CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END shipto_group ,CASE SUBSTRING(bc.bvclas,2,3)