/****** Object:  View [dbo].[V_PAINEL_NFE_EST_NF_ENT_IT_DEVOLUCAO_PENDENCIA_QTDE]    Script Date: 17/11/2018 11:00:00 ******/ 
IF EXISTS (SELECT * 
           FROM   SYS.VIEWS 
           WHERE  OBJECT_ID = 
      Object_id(N'[dbo].[V_PAINEL_NFE_EST_NF_ENT_IT_DEVOLUCAO_PENDENCIA_QTDE]')) 
  DROP VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_IT_DEVOLUCAO_PENDENCIA_QTDE] 

GO

--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_IT_DEVOLUCAO_PENDENCIA_QTDE
CREATE VIEW [dbo].[V_PAINEL_NFE_EST_NF_ENT_IT_DEVOLUCAO_PENDENCIA_QTDE] AS
SELECT COUNT(DISTINCT EST_NF_ENT_IT_DEVOLUCAO.CD_NF) AS QTDE_DEVOLUCAO
FROM EST_NF_ENT_IT_DEVOLUCAO WITH (NOLOCK)
WHERE (EST_NF_ENT_IT_DEVOLUCAO.QTDE_PROD - EST_NF_ENT_IT_DEVOLUCAO.QTDE_PROD_DEVO_GERADA) > 0