
IF EXISTS (SELECT * FROM SYSOBJECTS O, SYSUSERS U
           WHERE
           O.NAME = 'ESTVENDA' AND
	   TYPE = 'V' 		  AND
	   U.UID = O.UID          AND
	   U.NAME = USER)

   DROP VIEW ESTVENDA
GO

CREATE VIEW ESTVENDA AS
   SELECT P.CDFILIAL,
          P.CDPRODUTO,
          SUM(P.QTTOTALESTOQ) AS QTTOTALESTOQ
   FROM POSESTATU P, LOCALESTOQUE L
   WHERE (L.CDFILIAL     = P.CDFILIAL)     AND
         (L.CDALMOXARIFE = P.CDALMOXARIFE) AND
         (L.CDLOCALESTOQ = P.CDLOCALESTOQ) AND
         (L.IDDISPCONPED = 'S')
   GROUP BY P.CDFILIAL,
            P.CDPRODUTO
GO
