/****** Object:  View [dbo].[V_CHQ_LANC_CPL_FLUXO_CAIXA]    Script Date: 04/14/2014 17:08:57 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_CHQ_LANC_CPL_FLUXO_CAIXA]'))
DROP VIEW [dbo].[V_CHQ_LANC_CPL_FLUXO_CAIXA]
GO
GO
GO
--SELECT * FROM V_CHQ_LANC_CPL_FLUXO_CAIXA
CREATE VIEW [dbo].[V_CHQ_LANC_CPL_FLUXO_CAIXA] AS
SELECT     
	BC_LANC.CD_EMP,
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ, 
	PG_TP_FORN.CD_TP_FORN,
	BC_CONTAS.FLAG_FLUXO,
	BC_LANC.TP_LANC,
	BC_LANC.CD_CNT,
	'DEPOSITO CUSTODIA VISTA' AS ORIGEM,
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON,
	PG_TP_FORN.DS_TP,
	PG_TP_FORN.STS_TP
FROM         
	CHQ_LANC_CUSTODIA_CPL INNER JOIN 
	CHQ_EMI INNER JOIN CHQ_LANC_CPL ON 
	CHQ_EMI.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
	CHQ_EMI.CD_EMI = CHQ_LANC_CPL.CD_EMI ON 
    CHQ_LANC_CUSTODIA_CPL.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_LANC_CUSTODIA_CPL.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
    INNER JOIN BC_LANC_CHQ_LANC_CUSTODIA 
    INNER JOIN BC_CONTAS 
    INNER JOIN BC_LANC ON 
    BC_CONTAS.CD_EMP = BC_LANC.CD_EMP AND 
	BC_CONTAS.CD_CNT = BC_LANC.CD_CNT ON 
	BC_LANC_CHQ_LANC_CUSTODIA.CD_EMP = BC_LANC.CD_EMP AND 
    BC_LANC_CHQ_LANC_CUSTODIA.CD_BC_LANC = BC_LANC.CD_BC_LANC 
    INNER JOIN CHQ_LANC_CUSTODIA ON 
    BC_LANC_CHQ_LANC_CUSTODIA.CD_EMP = CHQ_LANC_CUSTODIA.CD_EMP AND 
    BC_LANC_CHQ_LANC_CUSTODIA.ANO = CHQ_LANC_CUSTODIA.ANO AND 
    BC_LANC_CHQ_LANC_CUSTODIA.CD_CUSTODIA = CHQ_LANC_CUSTODIA.CD_CUSTODIA ON
    CHQ_LANC_CUSTODIA_CPL.CD_EMP = CHQ_LANC_CUSTODIA.CD_EMP AND 
    CHQ_LANC_CUSTODIA_CPL.ANO = CHQ_LANC_CUSTODIA.ANO AND 
    CHQ_LANC_CUSTODIA_CPL.CD_CUSTODIA = CHQ_LANC_CUSTODIA.CD_CUSTODIA 
    INNER JOIN RC_TP_LANC ON 
    BC_LANC.CD_EMP = RC_TP_LANC.CD_EMP AND 
    BC_LANC.CD_TP_LANC = RC_TP_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN ON 
    RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
    RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON
    BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND
    BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
    INNER JOIN CHQ_LANC_CUSTODIA_CHQ_DEPOS ON 
    CHQ_LANC_CUSTODIA.CD_EMP = CHQ_LANC_CUSTODIA_CHQ_DEPOS.CD_EMP AND 
    CHQ_LANC_CUSTODIA.ANO = CHQ_LANC_CUSTODIA_CHQ_DEPOS.ANO AND 
    CHQ_LANC_CUSTODIA.CD_CUSTODIA = CHQ_LANC_CUSTODIA_CHQ_DEPOS.CD_CUSTODIA 
WHERE
	 CHQ_LANC_CPL.DT_EMI = CHQ_LANC_CPL.DT_VENCTO 
	 AND BC_LANC.VLR_LANC > 0 
	 AND BC_LANC_CHQ_LANC_CUSTODIA.TP_LANC = 1
UNION ALL
SELECT     
	BC_LANC.CD_EMP,
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ, 
	PG_TP_FORN.CD_TP_FORN,
	BC_CONTAS.FLAG_FLUXO,
	BC_LANC.TP_LANC,
	BC_LANC.CD_CNT,
	'REDEPOSITO' AS ORIGEM,
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON,
	PG_TP_FORN.DS_TP,
	PG_TP_FORN.STS_TP
FROM         
	CHQ_REDEPOS INNER JOIN CHQ_EMI 
	INNER JOIN CHQ_LANC_CPL ON 
    CHQ_EMI.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_EMI.CD_EMI = CHQ_LANC_CPL.CD_EMI ON 
    CHQ_REDEPOS.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_REDEPOS.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
    INNER JOIN BC_LANC_CHQ_REDEPOS 
    INNER JOIN BC_CONTAS 
    INNER JOIN BC_LANC ON 
    BC_CONTAS.CD_EMP = BC_LANC.CD_EMP AND 
    BC_CONTAS.CD_EMP = BC_LANC.CD_EMP AND 
    BC_CONTAS.CD_CNT = BC_LANC.CD_CNT AND 
    BC_CONTAS.CD_CNT = BC_LANC.CD_CNT ON 
    BC_LANC_CHQ_REDEPOS.CD_EMP = BC_LANC.CD_EMP AND 
    BC_LANC_CHQ_REDEPOS.CD_BC_LANC = BC_LANC.CD_BC_LANC ON 
    CHQ_REDEPOS.CD_EMP = BC_LANC_CHQ_REDEPOS.CD_EMP AND 
    CHQ_REDEPOS.CD_REDEPOS = BC_LANC_CHQ_REDEPOS.CD_REDEPOS 
    INNER JOIN RC_TP_LANC ON 
    BC_LANC.CD_EMP = RC_TP_LANC.CD_EMP AND 
    BC_LANC.CD_TP_LANC = RC_TP_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN ON 
    RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
    RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON
    BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND
    BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
UNION ALL	
SELECT     
	BC_LANC.CD_EMP,
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ, 
	PG_TP_FORN.CD_TP_FORN,
	BC_CONTAS.FLAG_FLUXO,
	BC_LANC.TP_LANC,
	BC_LANC.CD_CNT,
	'DEPOSITO' AS ORIGEM,
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON,
	PG_TP_FORN.DS_TP,
	PG_TP_FORN.STS_TP
FROM         
	BC_LANC INNER JOIN BC_LANC_CHQ_DEPOS ON 
	BC_LANC.CD_EMP = BC_LANC_CHQ_DEPOS.CD_EMP AND 
	BC_LANC.CD_BC_LANC = BC_LANC_CHQ_DEPOS.CD_BC_LANC 
	INNER JOIN CHQ_DEPOS ON 
	BC_LANC_CHQ_DEPOS.CD_EMP = CHQ_DEPOS.CD_EMP AND 
	BC_LANC_CHQ_DEPOS.ANO = CHQ_DEPOS.ANO AND 
    BC_LANC_CHQ_DEPOS.CD_DEPOS = CHQ_DEPOS.CD_DEPOS 
    INNER JOIN CHQ_DEPOS_CPL ON 
    CHQ_DEPOS.CD_EMP = CHQ_DEPOS_CPL.CD_EMP AND 
    CHQ_DEPOS.ANO = CHQ_DEPOS_CPL.ANO AND 
    CHQ_DEPOS.CD_DEPOS = CHQ_DEPOS_CPL.CD_DEPOS 
    INNER JOIN CHQ_LANC_CPL ON 
    CHQ_DEPOS_CPL.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_DEPOS_CPL.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
    INNER JOIN BC_CONTAS ON 
    BC_LANC.CD_EMP = BC_CONTAS.CD_EMP AND 
    BC_LANC.CD_CNT = BC_CONTAS.CD_CNT 
    INNER JOIN CHQ_EMI ON 
    CHQ_LANC_CPL.CD_EMP = CHQ_EMI.CD_EMP AND 
    CHQ_LANC_CPL.CD_EMI = CHQ_EMI.CD_EMI 
    INNER JOIN RC_TP_LANC ON 
    BC_LANC.CD_EMP = RC_TP_LANC.CD_EMP AND 
    BC_LANC.CD_TP_LANC = RC_TP_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN ON 
    RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
    RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON
    BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND
    BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
UNION ALL	
SELECT     
	BC_LANC.CD_EMP,
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ, 
	PG_TP_FORN.CD_TP_FORN,
	BC_CONTAS.FLAG_FLUXO,
	BC_LANC.TP_LANC,
	BC_LANC.CD_CNT,
	'DEVOLUCAO' AS ORIGEM,
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON,
	PG_TP_FORN.DS_TP,
	PG_TP_FORN.STS_TP
FROM         
	RC_TP_LANC INNER JOIN BC_CONTAS 
	INNER JOIN BC_LANC ON 
	BC_CONTAS.CD_EMP = BC_LANC.CD_EMP AND 
	BC_CONTAS.CD_CNT = BC_LANC.CD_CNT ON 
	RC_TP_LANC.CD_EMP = BC_LANC.CD_EMP AND 
    RC_TP_LANC.CD_TP_LANC = BC_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN ON 
    RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
    RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN 
    INNER JOIN BC_LANC_CHQ_DEVO ON 
    BC_LANC.CD_EMP = BC_LANC_CHQ_DEVO.CD_EMP AND 
    BC_LANC.CD_BC_LANC = BC_LANC_CHQ_DEVO.CD_BC_LANC 
    INNER JOIN CHQ_DEVO 
    INNER JOIN CHQ_EMI 
    INNER JOIN CHQ_LANC_CPL ON 
    CHQ_EMI.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_EMI.CD_EMI = CHQ_LANC_CPL.CD_EMI ON 
    CHQ_DEVO.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_DEVO.CD_CHQ = CHQ_LANC_CPL.CD_CHQ ON 
    BC_LANC_CHQ_DEVO.CD_EMP = CHQ_DEVO.CD_EMP AND
    BC_LANC_CHQ_DEVO.CD_DEVO = CHQ_DEVO.CD_DEVO
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON
    BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND
    BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
UNION ALL
SELECT     
	BC_LANC.CD_EMP, 
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ, 
    PG_TP_FORN.CD_TP_FORN, 
    BC_CONTAS.FLAG_FLUXO, 
    BC_LANC.TP_LANC, 
    BC_LANC.CD_CNT, 
    'RECEBIMENTO LOTE DE CHEQUES' AS ORIGEM, 
    BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON, 
    PG_TP_FORN.DS_TP, 
    PG_TP_FORN.STS_TP
FROM         
	CHQ_LANC_CHQ_LANC_CPL INNER JOIN CHQ_EMI 
	INNER JOIN CHQ_LANC_CPL ON 
    CHQ_EMI.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_EMI.CD_EMI = CHQ_LANC_CPL.CD_EMI ON 
    CHQ_LANC_CHQ_LANC_CPL.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_LANC_CHQ_LANC_CPL.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
    INNER JOIN RC_TP_LANC 
    INNER JOIN BC_CONTAS 
    INNER JOIN BC_LANC ON 
    BC_CONTAS.CD_EMP = BC_LANC.CD_EMP AND 
    BC_CONTAS.CD_CNT = BC_LANC.CD_CNT ON 
    RC_TP_LANC.CD_EMP = BC_LANC.CD_EMP AND 
    RC_TP_LANC.CD_TP_LANC = BC_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN ON 
    RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
    RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN 
    INNER JOIN BC_CONTAS_PRC_GRP_ECON ON 
    BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND 
    BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
    INNER JOIN BC_LANC_CHQ_LANC ON 
    BC_LANC.CD_EMP = BC_LANC_CHQ_LANC.CD_EMP AND 
    BC_LANC.CD_BC_LANC = BC_LANC_CHQ_LANC.CD_BC_LANC ON 
    CHQ_LANC_CHQ_LANC_CPL.CD_EMP = BC_LANC_CHQ_LANC.CD_EMP AND 
    CHQ_LANC_CHQ_LANC_CPL.ANO = BC_LANC_CHQ_LANC.ANO AND 
    CHQ_LANC_CHQ_LANC_CPL.CD_CHQ_LANC = BC_LANC_CHQ_LANC.CD_CHQ_LANC
UNION ALL
SELECT        
	BC_LANC.CD_EMP, 
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ,
	 PG_TP_FORN.CD_TP_FORN,  
	BC_CONTAS.FLAG_FLUXO, 
	BC_LANC.TP_LANC, 
    BC_LANC.CD_CNT, 
	'TRANSFERENCIA DE CHEQUES ENTRE CONTAS - DEBITO' AS ORIGEM, 
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON, 
	PG_TP_FORN.DS_TP, 
	PG_TP_FORN.STS_TP
FROM            
	RC_TP_LANC INNER JOIN PG_TP_FORN ON 
	RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
	RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN 
	INNER JOIN BC_LANC 
	INNER JOIN CHQ_LANC_CPL_TRANSF ON 
	BC_LANC.CD_EMP = CHQ_LANC_CPL_TRANSF.CD_EMP AND 
	BC_LANC.CD_BC_LANC = CHQ_LANC_CPL_TRANSF.CD_BC_LANC_ORIG 
	INNER JOIN CHQ_LANC_CPL ON 
	CHQ_LANC_CPL_TRANSF.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
	CHQ_LANC_CPL_TRANSF.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
	INNER JOIN CHQ_EMI ON 
	CHQ_LANC_CPL.CD_EMP = CHQ_EMI.CD_EMP AND 
	CHQ_LANC_CPL.CD_EMI = CHQ_EMI.CD_EMI 
	INNER JOIN BC_CONTAS ON 
	BC_LANC.CD_EMP = BC_CONTAS.CD_EMP AND 
	BC_LANC.CD_CNT = BC_CONTAS.CD_CNT ON 
	RC_TP_LANC.CD_TP_LANC = BC_LANC.CD_TP_LANC AND 
    RC_TP_LANC.CD_EMP = BC_LANC.CD_EMP 
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON 
	BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND 
	BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT
UNION ALL
SELECT        
	BC_LANC.CD_EMP, 
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	CHQ_LANC_CPL.VLR_CHQ,
	 PG_TP_FORN.CD_TP_FORN,  
	BC_CONTAS.FLAG_FLUXO, 
	BC_LANC.TP_LANC, 
    BC_LANC.CD_CNT, 
	'TRANSFERENCIA DE CHEQUES ENTRE CONTAS - CREDITO' AS ORIGEM, 
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON, 
	PG_TP_FORN.DS_TP, 
	PG_TP_FORN.STS_TP
FROM            
	RC_TP_LANC INNER JOIN PG_TP_FORN ON 
	RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP AND 
	RC_TP_LANC.CD_CLASS_FLUXO_CX = PG_TP_FORN.CD_TP_FORN 
	INNER JOIN BC_LANC 
	INNER JOIN CHQ_LANC_CPL_TRANSF ON 
	BC_LANC.CD_EMP = CHQ_LANC_CPL_TRANSF.CD_EMP AND 
	BC_LANC.CD_BC_LANC = CHQ_LANC_CPL_TRANSF.CD_BC_LANC_DEST
	INNER JOIN CHQ_LANC_CPL ON 
	CHQ_LANC_CPL_TRANSF.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
	CHQ_LANC_CPL_TRANSF.CD_CHQ = CHQ_LANC_CPL.CD_CHQ 
	INNER JOIN CHQ_EMI ON 
	CHQ_LANC_CPL.CD_EMP = CHQ_EMI.CD_EMP AND 
	CHQ_LANC_CPL.CD_EMI = CHQ_EMI.CD_EMI 
	INNER JOIN BC_CONTAS ON 
	BC_LANC.CD_EMP = BC_CONTAS.CD_EMP AND 
	BC_LANC.CD_CNT = BC_CONTAS.CD_CNT ON 
	RC_TP_LANC.CD_TP_LANC = BC_LANC.CD_TP_LANC AND 
    RC_TP_LANC.CD_EMP = BC_LANC.CD_EMP 
	INNER JOIN BC_CONTAS_PRC_GRP_ECON ON 
	BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP AND 
	BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT

	UNION ALL

  SELECT     
	BC_LANC.CD_EMP,
	BC_LANC.CD_BC_LANC, 
	CHQ_EMI.CGC_CPF, 
	CHQ_EMI.NM_EMI, 
	BC_LANC.DT_LANCTO, 
	BC_LANC.VLR_LANC VLR_CHQ, 
	PG_TP_FORN.CD_TP_FORN,
	BC_CONTAS.FLAG_FLUXO,
	BC_LANC.TP_LANC,
	BC_LANC.CD_CNT,
	'ACERTO CHEQUE DEVOLVIDO' AS ORIGEM,
	BC_CONTAS_PRC_GRP_ECON.CD_GRP_ECON,
	PG_TP_FORN.DS_TP,
	PG_TP_FORN.STS_TP

FROM         
	BC_LANC_CHQ_DEST_ENV_CPL INNER JOIN BC_LANC ON 
	BC_LANC_CHQ_DEST_ENV_CPL.CD_EMP = BC_LANC.CD_EMP AND
	BC_LANC_CHQ_DEST_ENV_CPL.CD_BC_LANC = BC_LANC.CD_BC_LANC

	INNER JOIN BC_CONTAS 
            ON BC_LANC.CD_EMP = BC_CONTAS.CD_EMP 
                AND BC_LANC.CD_CNT = BC_CONTAS.CD_CNT 
    INNER JOIN BC_CONTAS_PRC_GRP_ECON 
            ON BC_CONTAS.CD_EMP = BC_CONTAS_PRC_GRP_ECON.CD_EMP 
                AND BC_CONTAS.CD_CNT = BC_CONTAS_PRC_GRP_ECON.CD_CNT 
    INNER JOIN RC_TP_LANC 
            ON BC_LANC.CD_EMP = RC_TP_LANC.CD_EMP 
                AND BC_LANC.CD_TP_LANC = RC_TP_LANC.CD_TP_LANC 
    INNER JOIN PG_TP_FORN 
            ON RC_TP_LANC.CD_EMP = PG_TP_FORN.CD_EMP 
                AND RC_TP_LANC.CD_CLASS_FLUXO_CX = 
                    PG_TP_FORN.CD_TP_FORN 
	INNER JOIN CHQ_LANC_CPL ON 
	 CHQ_LANC_CPL.Cd_Emp = BC_LANC_CHQ_DEST_ENV_CPL.Cd_Emp 
	 AND CHQ_LANC_CPL.CD_CHQ=BC_LANC_CHQ_DEST_ENV_CPL.CD_CHQ 

	INNER JOIN CHQ_EMI ON 
 
    CHQ_EMI.CD_EMP = CHQ_LANC_CPL.CD_EMP AND 
    CHQ_EMI.CD_EMI = CHQ_LANC_CPL.CD_EMI 