IF  EXISTS (SELECT * FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_QTDE]'))
DROP VIEW [DBO].[V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_QTDE]    
GO
--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_QTDE
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_CANCEL_PENDENCIA_QTDE
AS
SELECT
	COUNT(CD_NF) AS QTDE_NF_ENT
FROM
(SELECT
	EST_NF_ENT.CD_NF
FROM
	EST_NF_ENT INNER JOIN EST_NF_ENT_CANCEL ON
	EST_NF_ENT.CD_EMP = EST_NF_ENT_CANCEL.CD_EMP AND
	EST_NF_ENT.CD_FILIAL = EST_NF_ENT_CANCEL.CD_FILIAL AND
	EST_NF_ENT.CD_NF = EST_NF_ENT_CANCEL.CD_NF 
	INNER JOIN EST_NF_ENT_NFE_CANCEL_PEND ON
	EST_NF_ENT.CD_EMP = EST_NF_ENT_NFE_CANCEL_PEND.CD_EMP AND
	EST_NF_ENT.CD_FILIAL = EST_NF_ENT_NFE_CANCEL_PEND.CD_FILIAL AND
	EST_NF_ENT.CD_NF = EST_NF_ENT_NFE_CANCEL_PEND.CD_NF
	LEFT OUTER JOIN EST_NF_ENT_NFE_CANCEL_ERR ON
	EST_NF_ENT.CD_EMP = EST_NF_ENT_NFE_CANCEL_ERR.CD_EMP AND
	EST_NF_ENT.CD_FILIAL = EST_NF_ENT_NFE_CANCEL_ERR.CD_FILIAL AND
	EST_NF_ENT.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) AS RS