IF  EXISTS (SELECT * FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_ANALITICO]'))
DROP VIEW [DBO].[V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_ANALITICO]    
GO
--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_ANALITICO
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_ANALITICO
AS
SELECT
    V_EST_NF_ENT_CAB.CD_FILIAL,
	V_EST_NF_ENT_CAB.NR_NF,
	V_EST_NF_ENT_CAB.NM_ORIG,
	V_EST_NF_ENT_CAB.NR_AUTORIZADOR,
	V_EST_NF_ENT_CAB.NR_PROTOCOLO,
	EST_NF_ENT_CANCEL.DT_CANCEL,
	'CANCELAMENTO TRANSACAO' AS TIPO_TRANSACAO
FROM
	V_EST_NF_ENT_CAB INNER JOIN EST_NF_ENT_CANCEL ON
	V_EST_NF_ENT_CAB.CD_EMP = EST_NF_ENT_CANCEL.CD_EMP AND
	V_EST_NF_ENT_CAB.CD_FILIAL = EST_NF_ENT_CANCEL.CD_FILIAL AND
	V_EST_NF_ENT_CAB.CD_NF = EST_NF_ENT_CANCEL.CD_NF 
	INNER JOIN EST_NF_ENT_NFE_CANCEL_PEND ON
	V_EST_NF_ENT_CAB.CD_EMP = EST_NF_ENT_NFE_CANCEL_PEND.CD_EMP AND
	V_EST_NF_ENT_CAB.CD_FILIAL = EST_NF_ENT_NFE_CANCEL_PEND.CD_FILIAL AND
	V_EST_NF_ENT_CAB.CD_NF = EST_NF_ENT_NFE_CANCEL_PEND.CD_NF
	LEFT OUTER JOIN EST_NF_ENT_NFE_CANCEL_ERR ON
	V_EST_NF_ENT_CAB.CD_EMP = EST_NF_ENT_NFE_CANCEL_ERR.CD_EMP AND
	V_EST_NF_ENT_CAB.CD_FILIAL = EST_NF_ENT_NFE_CANCEL_ERR.CD_FILIAL AND
	V_EST_NF_ENT_CAB.CD_NF = EST_NF_ENT_NFE_CANCEL_ERR.CD_NF 
WHERE
	EST_NF_ENT_NFE_CANCEL_ERR.CD_NF IS NULL
	AND EST_NF_ENT_NFE_CANCEL_PEND.PEND_SOLUC<> 2