/****** Object:  View [dbo].[V_RC_DEB_VLR_PGTO_CNT]    Script Date: 04/14/2014 17:08:57 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_RC_DEB_VLR_PGTO_CNT]'))
DROP VIEW [dbo].[V_RC_DEB_VLR_PGTO_CNT]
GO
GO
GO
CREATE VIEW [dbo].[V_RC_DEB_VLR_PGTO_CNT]
AS
SELECT     
	dbo.RC_CRED.CD_EMP, 
	dbo.RC_CRED.CD_FILIAL, 
	dbo.RC_CRED.CD_RC_DEB, 
	SUM(dbo.RC_CRED.VL_PGTO) AS VLR_PGTO, 
    SUM(dbo.RC_CRED.VL_JUR) AS VL_JUR, 
	SUM(dbo.RC_CRED.VL_DESC) AS VL_DESC, 
	ISNULL(BC_CONTAS.AGC_CNT,'') AS AGC_CNT, 
	ISNULL(dbo.BC_CONTAS.NR_CNT,'CONTA NAO ENCONTRADA') AS NR_CNT, 
    ISNULL(dbo.BC_CONTAS.CD_CNT,0) AS CD_CNT, 
	ISNULL(dbo.BC_BANCO.CD_BC,'') AS CD_BC, 
	ISNULL(dbo.BC_BANCO.DS_BC,'') AS DS_BC, 
	SUM (dbo.RC_CRED.VLR_GLOSA)VLR_GLOSA
FROM         
	dbo.RC_CRED 
	LEFT OUTER JOIN dbo.BC_CONTAS ON 
	dbo.RC_CRED.CD_EMP = dbo.BC_CONTAS.CD_EMP AND 
	dbo.RC_CRED.CD_CNT = dbo.BC_CONTAS.CD_CNT 
	LEFT OUTER JOIN dbo.BC_BANCO ON 
	dbo.BC_CONTAS.CD_EMP = dbo.BC_BANCO.CD_EMP AND 
	dbo.BC_CONTAS.CD_BC = dbo.BC_BANCO.CD_BC
GROUP BY
	dbo.RC_CRED.CD_EMP, 
	dbo.RC_CRED.CD_FILIAL, 
	dbo.RC_CRED.CD_RC_DEB, 
	dbo.BC_CONTAS.AGC_CNT, 
	dbo.BC_CONTAS.NR_CNT, 
    dbo.BC_CONTAS.CD_CNT, 
	dbo.BC_BANCO.CD_BC, 
	dbo.BC_BANCO.DS_BC
GO


