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_IMPOSTO_NOTAF')
   DROP VIEW V_IMPOSTO_NOTAF
GO

CREATE VIEW V_IMPOSTO_NOTAF
AS
   SELECT I.CDFILIAL, I.NRLANCTONF, I.CDIMPOSTO, I.NRIMPOSNF, I.VRCONTABILNF, I.VRPERREDBCNF,
          I.VRBASECALCNF, I.VRALIQNF, I.VRPARDEDNF, I.VRIMPOSTONF, I.CDFISCALNF, I.CDSITUTRIBNF,
          I.CDFISCOPERNF, I.CDSUFXCFOPNF, I.NRSEQUMAPAPU, I.DSOBSFISCIT, I.DTCOMPETAPUR, I.IDIMPOSTONF,
          I.CDCCTBLIMPNF, I.NRSEQMAPOIMP, I.DTVENCNFAPPG, I.IDTRIMPOSTNF, I.VRENCBCALCNF,
          I.CDSITUTRIBIMNFE, I.VRIMPCARGATRIBI,

          N.CDEMPRESA, N.CDINSCESTA, N.CDINSCMUNI, N.IDTPIJURNF, N.NRINSJURNF, N.CDFORNECED, N.CDCLIENTE,
          N.NRNOTAFISC, N.DTEMISSAO, N.DTENTRSAID, N.VRNOTAFISC, N.IDENTRSAIDOP, N.CDTIPOOPER,
          N.CDSERIE, N.IDSTATUS, N.CDSERIEEMIS, N.IDSISTEMA, N.CDMODDOCFISC, N.CDSERIEENTR, N.IDORIGDESTNF,
          N.CDFILIEMIT, N.CDFILIRECE, N.IDIMPNFPA, N.NRNOTAFISCALELE, N.NRACESSONFE, N.IDEXPNFEP, N.DTCANCELANF,
          N.IDEXPNFEMANAUS, N.IDSTATUSNFE, N.IDEXPNFESANAND

     FROM NOTAFISCAL N, IMPOSTONF I
    WHERE N.CDFILIAL = I.CDFILIAL
      AND N.NRLANCTONF = I.NRLANCTONF
      AND ((N.IDSTATUS = 'E') OR (N.IDSTATUS = 'A'))
GO

