/****** Object:  View [dbo].[V_EST_NF_SAI_CHECKIN_SEM_RESSUPRIMENTO]    Script Date: 05/08/2013 09:22:37 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_EST_NF_SAI_CHECKIN_SEM_RESSUPRIMENTO]'))
DROP VIEW [dbo].[V_EST_NF_SAI_CHECKIN_SEM_RESSUPRIMENTO]
GO
GO
--SELECT * FROM V_EST_NF_SAI_CHECKIN_SEM_RESSUPRIMENTO WHERE CD_FILIAL_DEST = 90 AND QT_IT_NOTA_SAIDA <> QT_IT_CHECK
CREATE VIEW V_EST_NF_SAI_CHECKIN_SEM_RESSUPRIMENTO AS 
SELECT
	
	EST_NF_SAI_IT.CD_EMP,
	EST_NF_SAI_IT.CD_FILIAL AS CD_FILIAL_ORIG,
	EST_NF_ENT_EST_NF_SAI_TRANSF.CD_FIL_DEST AS CD_FILIAL_DEST,
	EST_NF_ENT_EST_NF_SAI_TRANSF.CD_NF_SAI,
	EST_NF_ENT_EST_NF_SAI_TRANSF.CD_NF_ENT,
	EST_NF_ENT.DT_ENT,
	EST_NF_SAI_IT.CD_PROD,
	EST_NF_SAI_IT.QT_IT AS QT_IT_NOTA_SAIDA,
	ISNULL(EST_NF_SAI_CHECKIN_ENTRADA_CPL.QT_IT_CHECK,0) AS QT_IT_CHECK
FROM
	EST_NF_SAI_IT 
	LEFT JOIN EST_NF_SAI_CHECKIN_ENTRADA_CPL ON
		EST_NF_SAI_IT.CD_EMP = EST_NF_SAI_CHECKIN_ENTRADA_CPL.CD_EMP AND
		EST_NF_SAI_IT.CD_FILIAL = EST_NF_SAI_CHECKIN_ENTRADA_CPL.CD_FILIAL AND
		EST_NF_SAI_IT.CD_NF = EST_NF_SAI_CHECKIN_ENTRADA_CPL.CD_NF AND
		EST_NF_SAI_IT.CD_PROD = EST_NF_SAI_CHECKIN_ENTRADA_CPL.CD_PROD  
	INNER JOIN  EST_NF_ENT_EST_NF_SAI_TRANSF ON
		EST_NF_SAI_IT.CD_EMP = EST_NF_ENT_EST_NF_SAI_TRANSF.CD_EMP AND
		EST_NF_SAI_IT.CD_FILIAL = EST_NF_ENT_EST_NF_SAI_TRANSF.CD_FIL_ORIG AND
		EST_NF_SAI_IT.CD_NF = EST_NF_ENT_EST_NF_SAI_TRANSF.CD_NF_SAI
	INNER JOIN EST_NF_ENT ON
		EST_NF_ENT_EST_NF_SAI_TRANSF.CD_EMP = EST_NF_ENT.CD_EMP AND
		EST_NF_ENT_EST_NF_SAI_TRANSF.CD_FIL_DEST = EST_NF_ENT.CD_FILIAL AND
		EST_NF_ENT_EST_NF_SAI_TRANSF.CD_NF_ENT = EST_NF_ENT.CD_NF
	
	