IF  EXISTS (SELECT * FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_CG_FND_VERBA_USO_CG_FND_VERBA_RECOMPOSICAO_VLR]'))

DROP VIEW [DBO].[V_CG_FND_VERBA_USO_CG_FND_VERBA_RECOMPOSICAO_VLR]    
GO
--SELECT * FROM V_CG_FND_VERBA_USO_CG_FND_VERBA_RECOMPOSICAO_VLR
CREATE VIEW V_CG_FND_VERBA_USO_CG_FND_VERBA_RECOMPOSICAO_VLR AS 
SELECT        
	CG_FND_VERBA_USO_CG_FND_VERBA.CD_EMP, 
	CG_FND_VERBA_USO_CG_FND_VERBA.CD_FND_VERBA, 
	CG_FND_VERBA_USO_PDV_VD_IT.CD_PROD, 
	ISNULL(SUM(CG_FND_VERBA_USO_PDV_VD_IT.VLR_USO),0) AS VLR_RECOMPOSICAO
FROM            
	CG_FND_VERBA_USO_CG_FND_VERBA INNER JOIN CG_FND_VERBA_USO_PDV_VD_IT ON 
	CG_FND_VERBA_USO_CG_FND_VERBA.CD_EMP = CG_FND_VERBA_USO_PDV_VD_IT.CD_EMP AND 
    CG_FND_VERBA_USO_CG_FND_VERBA.CD_FND_VERBA_USO = CG_FND_VERBA_USO_PDV_VD_IT.CD_FND_VERBA_USO
GROUP BY
	CG_FND_VERBA_USO_CG_FND_VERBA.CD_EMP, 
	CG_FND_VERBA_USO_CG_FND_VERBA.CD_FND_VERBA, 
	CG_FND_VERBA_USO_PDV_VD_IT.CD_PROD