IF EXISTS (SELECT 1 FROM sys.views   WHERE object_id = OBJECT_ID(N'[dbo].[V_EQUALS_FINAL]'))
    DROP VIEW V_EQUALS_FINAL;
GO

create view V_EQUALS_FINAL
as
SELECT 
    DISTINCT 
    CONCILIACAO_CARTOES_FINAL.CD_EMP		
    ,CONCILIACAO_CARTOES_FINAL.CD_FILIAL	
    ,CONCILIACAO_CARTOES_FINAL.CD_VD		
    ,CONCILIACAO_CARTOES_FINAL.CD_CTR_PDV_VD_TEF
    ,CONCILIACAO_CARTOES_FINAL.DT_VD
    ,CONCILIACAO_CARTOES_FINAL.CD_CX		
    ,CONCILIACAO_CARTOES_FINAL.NR_ECF	
    ,CONCILIACAO_CARTOES_FINAL.CD_CTR_PDV_CUPOM_NAO_FISCAL_TEF
    ,CONCILIACAO_CARTOES_FINAL.CD_RECTO_TEF
    ,CONCILIACAO_CARTOES_LINX_CONCILIADOR.IDT_LOTE_REDE

FROM 
    CONCILIACAO_CARTOES_FINAL INNER JOIN CONCILIACAO_CARTOES_LINX_CONCILIADOR on 
    CONCILIACAO_CARTOES_FINAL.CD_FILIAL = CONCILIACAO_CARTOES_LINX_CONCILIADOR.CD_FILIAL 
    AND CONCILIACAO_CARTOES_FINAL.CD_CTR_CONCILIADOR = CONCILIACAO_CARTOES_LINX_CONCILIADOR.CD_CTR
    AND CONCILIACAO_CARTOES_FINAL.IDT_TRANSACAO = CONCILIACAO_CARTOES_LINX_CONCILIADOR.IDT_TRANSACAO
WHERE
      CONCILIACAO_CARTOES_LINX_CONCILIADOR.CD_GRUPO NOT IN (141,142,143)
