IF  EXISTS (SELECT * FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_PAINEL_NFE_EST_NF_ENT_PRE_ENTRADA_BLQ_QTDE]'))
DROP VIEW [DBO].[V_PAINEL_NFE_EST_NF_ENT_PRE_ENTRADA_BLQ_QTDE]    
GO
--SELECT * FROM V_PAINEL_NFE_EST_NF_ENT_PRE_ENTRADA_BLQ_QTDE
CREATE VIEW V_PAINEL_NFE_EST_NF_ENT_PRE_ENTRADA_BLQ_QTDE
AS
SELECT  
	COUNT(EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA) AS QTDE_PRE_ENTRADA_BLQ
FROM  
	EST_NF_ENT_PRE_ENTRADA LEFT OUTER JOIN EST_NF_ENT_PRE_ENTRADA_CPL_CONF_LIB ON       
	EST_NF_ENT_PRE_ENTRADA.CD_EMP = EST_NF_ENT_PRE_ENTRADA_CPL_CONF_LIB.CD_EMP        AND 
	EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA = EST_NF_ENT_PRE_ENTRADA_CPL_CONF_LIB.CD_CTR_PRE_ENTRADA 
	INNER JOIN EST_NF_ENT_PRE_ENTRADA_PENDENCIA ON
	EST_NF_ENT_PRE_ENTRADA.CD_EMP = EST_NF_ENT_PRE_ENTRADA_PENDENCIA.CD_EMP AND
	EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA = EST_NF_ENT_PRE_ENTRADA_PENDENCIA.CD_CTR_PRE_ENTRADA
	LEFT OUTER JOIN EST_NF_ENT_PRE_ENTRADA_CPL_CONF_N_LIB CPL_CONF_N ON       
	EST_NF_ENT_PRE_ENTRADA.CD_EMP = CPL_CONF_N.CD_EMP        AND 
	EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA = CPL_CONF_N.CD_CTR_PRE_ENTRADA 
	LEFT OUTER JOIN EST_NF_ENT_PRE_ENTRADA_EST_WMS_ENT WMS ON       
	EST_NF_ENT_PRE_ENTRADA.CD_EMP = WMS.CD_EMP        AND 
	EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA = WMS.CD_CTR_PRE_ENTRADA 
WHERE 
	EST_NF_ENT_PRE_ENTRADA.CD_EMP = 1
	AND EXISTS (SELECT
					CD_EMP 
				FROM 
					EST_NF_ENT_PRE_ENTRADA_CPL_CONF AS CPL_CONF
				WHERE 
					CPL_CONF.CD_EMP = EST_NF_ENT_PRE_ENTRADA.CD_EMP AND
					CPL_CONF.CD_CTR_PRE_ENTRADA = EST_NF_ENT_PRE_ENTRADA.CD_CTR_PRE_ENTRADA) 
					AND EST_NF_ENT_PRE_ENTRADA_CPL_CONF_LIB.CD_EMP IS NULL  
	AND CPL_CONF_N.CD_EMP IS NULL 