CREATE OR REPLACE VIEW ESTCONSOLI
AS
SELECT POSESTCONS.CDFILIAL,
       POSESTCONS.CDPRODUTO,
       POSESTCONS.DTPOSESTCON,
       POSESTCONS.DTPOSESTCON DTULTAUTFOR,
       POSESTCONS.DTPOSESTCON DTULTLISTPRE,
       PRODFILI.DTULTCOMPR,
       POSESTCONS.QTESTDIACON,
       POSESTCONS.QTESTANTCON,
       POSESTCONS.VRESTDIACON,
       POSESTCONS.VRESTANTCON,
       POSESTCONS.VRESTBRUTCON,
       POSESTCONS.VRBRUTANTCON,
       POSESTCONS.IDPOSZEROCON,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                           (POSESTCONS.VRESTANTCON/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTDIACON/POSESTCONS.QTESTDIACON)) AS VRCUST1,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                        (POSESTCONS.VRBRUTANTCON/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTBRUTCON/POSESTCONS.QTESTDIACON)) AS VRCUST2,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                           (POSESTCONS.VRESTANTCON/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTDIACON/POSESTCONS.QTESTDIACON)) AS VRCUST3,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                        (POSESTCONS.VRBRUTANTCON/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTBRUTCON/POSESTCONS.QTESTDIACON)) AS VRCUST4,
       PRODFILI.VRULTCOMPR   AS VRCUST5,
       POSESTCONS.VRCUSPRLISTP AS VRCUST6,
       POSESTCONS.VRPRCUSTOAF AS VRCUST7,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                           (POSESTCONS.VRESTANTCOM1/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTDIACOM1/POSESTCONS.QTESTDIACON)) AS VRCUST20,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                           (POSESTCONS.VRESTANTCOM2/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTDIACOM2/POSESTCONS.QTESTDIACON)) AS VRCUST21,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                        (POSESTCONS.VRBRUTANTCM1/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTBRUTCM1/POSESTCONS.QTESTDIACON)) AS VRCUST22,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                        (POSESTCONS.VRBRUTANTCM2/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTBRUTCM2/POSESTCONS.QTESTDIACON)) AS VRCUST23,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
              0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                        0, 0,
                       (POSESTCONS.VRESTANTCOM1/POSESTCONS.QTESTANTCON)),
                 (POSESTCONS.VRESTDIACOM1/POSESTCONS.QTESTDIACON)) AS VRCUST24,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
             0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                       0, 0,
                      (POSESTCONS.VRESTANTCOM2/POSESTCONS.QTESTANTCON)),
               (POSESTCONS.VRESTDIACOM2/POSESTCONS.QTESTDIACON)) AS VRCUST25,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
             0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                       0, 0,
                      (POSESTCONS.VRBRUTANTCM1/POSESTCONS.QTESTANTCON)),
               (POSESTCONS.VRESTBRUTCM1/POSESTCONS.QTESTDIACON)) AS VRCUST26,
       DECODE(NVL(POSESTCONS.QTESTDIACON, 0),
             0, DECODE(NVL(POSESTCONS.QTESTANTCON, 0),
                       0, 0,
                      (POSESTCONS.VRBRUTANTCM2/POSESTCONS.QTESTANTCON)),
               (POSESTCONS.VRESTBRUTCM2/POSESTCONS.QTESTDIACON)) AS VRCUST27,
       PRODFILI.VRULTCOMPRM1 AS VRCUST28,
       PRODFILI.VRULTCOMPRM2 AS VRCUST29,
       POSESTCONS.VRCUSPRLISM1 AS VRCUST30,
       POSESTCONS.VRCUSPRLISM2 AS VRCUST31,
       POSESTCONS.VRPRCUSAFM1 AS VRCUST32,
       POSESTCONS.VRPRCUSAFM2 AS VRCUST33
FROM POSESTCONS, PRODFILI
WHERE (POSESTCONS.CDFILIAL    = PRODFILI.CDFILIAL)  AND
     (POSESTCONS.CDPRODUTO   = PRODFILI.CDPRODUTO)
/

