/****** Object:  View [dbo].[V_EST_NF_SAI_IT_DEV]    Script Date: 22/01/2015 18:08:26 ******/
IF EXISTS(SELECT * FROM SYS.OBJECTS WHERE NAME ='V_EST_NF_SAI_IT_DEV' AND TYPE = 'V')
BEGIN
	DROP VIEW [dbo].[V_EST_NF_SAI_IT_DEV]
END
GO
GO
CREATE VIEW [dbo].[V_EST_NF_SAI_IT_DEV] AS 
SELECT     
	EST_NF_SAI_NF_ENT.CD_EMP, 
	EST_NF_SAI_NF_ENT.CD_FILIAL, 
	EST_NF_SAI_NF_ENT.CD_NF_SAI, 
	EST_NF_ENT_IT.CD_PROD,
	SUM(EST_NF_ENT_IT.QT_IT) AS QT_IT_DEV
FROM         
	EST_NF_SAI_NF_ENT INNER JOIN EST_NF_ENT_IT ON 
	EST_NF_SAI_NF_ENT.CD_EMP = EST_NF_ENT_IT.CD_EMP AND 
	EST_NF_SAI_NF_ENT.CD_FILIAL = EST_NF_ENT_IT.CD_FILIAL AND 
    EST_NF_SAI_NF_ENT.CD_NF_ENT = EST_NF_ENT_IT.CD_NF
	INNER JOIN EST_NF_ENT ON
	EST_NF_SAI_NF_ENT.CD_EMP = EST_NF_ENT.CD_EMP AND
	EST_NF_SAI_NF_ENT.CD_FILIAL = EST_NF_ENT.CD_FILIAL AND
	EST_NF_SAI_NF_ENT.CD_NF_ENT = EST_NF_ENT.CD_NF 
WHERE
	EST_NF_ENT.STS_NF = 0
GROUP BY
	EST_NF_SAI_NF_ENT.CD_EMP, 
	EST_NF_SAI_NF_ENT.CD_FILIAL, 
	EST_NF_SAI_NF_ENT.CD_NF_SAI, 
	EST_NF_ENT_IT.CD_PROD
