IF OBJECT_ID('V_PAINEL_NFE_DANFE_ERROS_VALIDACAO_QTDE') IS NOT NULL
	 DROP VIEW	V_PAINEL_NFE_DANFE_ERROS_VALIDACAO_QTDE
GO
--SELECT * FROM V_PAINEL_NFE_DANFE_ERROS_VALIDACAO_QTDE	WITH (NOLOCK)
CREATE VIEW V_PAINEL_NFE_DANFE_ERROS_VALIDACAO_QTDE  AS
SELECT
	COUNT(EST_NF_ENT_DANFE_PROVISORIO.CD_CTR) AS QTDE_ERROS_VALIDACAO
FROM
	EST_NF_ENT_DANFE_PROVISORIO INNER JOIN EST_NF_ENT_DANFE_PROVISORIO_PENDENTE ON
	EST_NF_ENT_DANFE_PROVISORIO.CD_CTR = EST_NF_ENT_DANFE_PROVISORIO_PENDENTE.CD_CTR
	INNER JOIN EST_NF_ENT_NFE_FORN_VALID ON
	EST_NF_ENT_DANFE_PROVISORIO.CD_EMP = EST_NF_ENT_NFE_FORN_VALID.CD_EMP AND
	EST_NF_ENT_DANFE_PROVISORIO.CD_FILIAL = EST_NF_ENT_NFE_FORN_VALID.CD_FILIAL AND
	EST_NF_ENT_DANFE_PROVISORIO.NR_NF = EST_NF_ENT_NFE_FORN_VALID.NR_NF AND
	EST_NF_ENT_DANFE_PROVISORIO.CD_FORN = EST_NF_ENT_NFE_FORN_VALID.CD_FORN
WHERE
	NOT VALIDACAO IN (1,4,3)
	AND COALESCE(ERR_VALIDACAO,'')<>''