ALTER TABLE PARTFILI
ADD CDFILISUBGR VARCHAR2(4)
/
ALTER TABLE PARTFILI
ADD CDGRUPPROD VARCHAR2(10)
/
ALTER TABLE PARTFILI
ADD CDSUBGRPROD VARCHAR2(10)
/
CREATE INDEX PARTFILI_02 ON PARTFILI (CDFILISUBGR ASC, CDGRUPPROD ASC, CDSUBGRPROD ASC, CDPRODUTO ASC)
/
ALTER TABLE PARTFILI
ADD CONSTRAINT FK_PRSUBGRPROD_PARTFILI FOREIGN KEY (CDFILISUBGR, CDGRUPPROD, CDSUBGRPROD, CDPRODUTO)
    REFERENCES PRSUBGRPROD (CDFILISUBGR, CDGRUPPROD, CDSUBGRPROD, CDPRODUTO) ON DELETE CASCADE
/
UPDATE PARTFILI /* ACORDO SACAY */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000001'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J00623758000186' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000001')
/
COMMIT
/
UPDATE PARTFILI /* ACORDO GREENVEGS */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000002'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J02607477000165' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000002')
/
COMMIT
/
UPDATE PARTFILI /* ACORDO MARFRIG */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000003'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J03853896000140' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000003')
/
COMMIT
/
UPDATE PARTFILI /* ACORDO OLEO */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000004'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J04528629000240' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000004')
/
COMMIT
/
UPDATE PARTFILI /* ACORDO ARROZ */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000005'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J64904295000103' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000005')
/
COMMIT
/
UPDATE PARTFILI /* ACORDO OLEO BB */
SET CDFILISUBGR = 'P',
    CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003'),
    CDSUBGRPROD = '0000000006'
WHERE
   PARTFILI.CDTIPPART = '4' AND
   PARTFILI.CDFORNECED = 'J04528629000240' AND
   EXISTS(SELECT PRSUBGRPROD.CDGRUPPROD
          FROM PRSUBGRPROD
          WHERE
             PRSUBGRPROD.CDGRUPPROD = (SELECT PARASUPRI.CDGRUPPROD FROM PARASUPRI WHERE PARASUPRI.CDFILIAL = '0003') AND
             PRSUBGRPROD.CDFILISUBGR = 'P' AND
             PRSUBGRPROD.CDPRODUTO = PARTFILI.CDPRODUTO AND
             PRSUBGRPROD.CDSUBGRPROD = '0000000006')
/
COMMIT
/             
