IF EXISTS (SELECT * FROM SYS.VIEWS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[V_BC_LANC_DESC_TAXA]'))
    DROP VIEW [dbo].[V_BC_LANC_DESC_TAXA];
GO

CREATE VIEW [dbo].[V_BC_LANC_DESC_TAXA]
AS
SELECT BC_LANC.CD_EMP,
	  BC_LANC.CD_BC_LANC,
	  SUM(PG_CRED.VLR_DESP_OUTR) AS VLR_DESC_TAXA
FROM BC_LANC INNER JOIN PG_DEB_LOTE_BC_LANC ON 
    BC_LANC.CD_EMP = PG_DEB_LOTE_BC_LANC.CD_EMP AND 
    BC_LANC.CD_BC_LANC = PG_DEB_LOTE_BC_LANC.CD_BC_LANC
	
    INNER JOIN PG_DEB_LOTE_PG_DEB ON 
    PG_DEB_LOTE_BC_LANC.CD_EMP = PG_DEB_LOTE_PG_DEB.CD_EMP AND
    PG_DEB_LOTE_BC_LANC.CD_PG_DEB_LOTE = PG_DEB_LOTE_PG_DEB.CD_PG_DEB_LOTE
	
    INNER JOIN PG_CRED ON 
    PG_DEB_LOTE_PG_DEB.CD_EMP = PG_CRED.CD_EMP AND
    PG_DEB_LOTE_PG_DEB.CD_PG_CRED =PG_CRED.CD_PG_CRED AND
    PG_DEB_LOTE_PG_DEB.CD_FILIAL = PG_CRED.CD_FILIAL

WHERE BC_LANC.CD_EMP=1 

GROUP BY BC_LANC.CD_EMP,BC_LANC.CD_BC_LANC