IF EXISTS (SELECT *
             FROM SYSOBJECTS O, SYSUSERS U
            WHERE U.UID = O.UID        
              AND U.NAME = USER
              AND TYPE = 'V'
              AND O.NAME LIKE 'V_ITEM_IMPO_NOTAF')
   DROP VIEW V_ITEM_IMPO_NOTAF
GO

CREATE VIEW V_ITEM_IMPO_NOTAF
AS

   SELECT IT.CDFILIAL, IT.NRLANCTONF, IT.NRSEQITPROD, IT.NRITPROIMPOS, IT.VRALIQITEM, IT.CDIMPOSTO, IT.VRCONTITIMP,
          IT.VRPERREDBCIT,IT.VRBASECALCIT, IT.VRALIQITEM AS VRALIQIT, IT.VRPARDEDIT, IT.VRIMPOSTOIT, IT.CDFISCALIT,
          IT.CDSITUTRIBIT, IT.CDFISCOPERIT, IT.CDSUFXCFOPIT
     FROM ITEMPROIMPOS IT, NOTAFISCAL N
    WHERE N.CDFILIAL  = IT.CDFILIAL
      AND N.NRLANCTONF = IT.NRLANCTONF
      AND ((N.IDSTATUS = 'E') OR (N.IDSTATUS = 'A'))

GO
