/****** Object:  View [dbo].[V_CHQ_LANC_CPL]    Script Date: 07/18/2013 08:48:39 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_CHQ_LANC_CPL]'))
DROP VIEW [dbo].[V_CHQ_LANC_CPL]
GO
 
/*SELECT CAST(99999999999999999999 AS BIGINT) + 1
SELECT * FROM V_CHQ_LANC_CPL ORDER BY NR_CHQ DESC*/
CREATE VIEW [dbo].[V_CHQ_LANC_CPL]
AS
SELECT     TOP (100) PERCENT 

	dbo.CHQ_LANC_CPL.CD_EMP, 
	dbo.CHQ_LANC.ANO, 
	dbo.CHQ_LANC.CD_CHQ_LANC, 
	ISNULL(dbo.CHQ_LANC.CD_FILIAL, 0) AS CD_FILIAL, 
	dbo.CHQ_LANC.CD_CNT AS CD_CNT_LOTE, 
	dbo.CHQ_LANC.VLR_LANC, 
	dbo.CHQ_LANC.HIST_LANC, 
	dbo.CHQ_LANC_CPL.CD_CHQ, 
    dbo.CHQ_LANC_CPL.CD_EMI, 
	dbo.CHQ_EMI.CGC_CPF, 
	dbo.CHQ_EMI.NM_EMI, 
	dbo.CHQ_LANC_CPL.NR_CHQ, 
	dbo.CHQ_LANC_CPL.SR_CHQ, 
    dbo.CHQ_LANC_CPL.ANO_CHQ, 
	dbo.CHQ_LANC_CPL.CD_BC_CHQ, 
	dbo.CHQ_LANC_CPL.AG_CHQ, 
	dbo.CHQ_LANC_CPL.NR_CNT_CHQ, 
    dbo.CHQ_LANC_CPL.VLR_CHQ, 
	dbo.CHQ_LANC_CPL.DT_VENCTO, 
	dbo.CHQ_LANC_CPL.DT_EMI, 
	dbo.CHQ_LANC.DT_RECEB, 
    dbo.PRC_GRP_ECON_PRC_FILIAL.CD_GRP_ECON,		
	dbo.CHQ_EMI.END_EMI,
	dbo.CHQ_EMI.FONE_EMI,
	dbo.CHQ_LANC_CPL.COMP,
	dbo.BC_PRACA_COMPENSACAO.NM_PRACA_COMPENSACAO,
	CHQ_LANC_CPL.STS_CHQ,
	CHQ_LANC_CPL.CMC7,
	CHQ_LANC_CPL.CD_CNT,
	C.DS_CNT
FROM         
	dbo.CHQ_LANC_CHQ_LANC_CPL 
	RIGHT OUTER JOIN dbo.CHQ_LANC 
	LEFT OUTER JOIN dbo.PRC_GRP_ECON_PRC_FILIAL ON 
	dbo.CHQ_LANC.CD_EMP = dbo.PRC_GRP_ECON_PRC_FILIAL.CD_EMP AND 
    dbo.CHQ_LANC.CD_FILIAL = dbo.PRC_GRP_ECON_PRC_FILIAL.CD_FILIAL ON 
    dbo.CHQ_LANC_CHQ_LANC_CPL.CD_EMP = dbo.CHQ_LANC.CD_EMP AND 
	dbo.CHQ_LANC_CHQ_LANC_CPL.ANO = dbo.CHQ_LANC.ANO AND 
    dbo.CHQ_LANC_CHQ_LANC_CPL.CD_CHQ_LANC = dbo.CHQ_LANC.CD_CHQ_LANC 
	FULL OUTER JOIN dbo.CHQ_EMI 
	INNER JOIN dbo.CHQ_LANC_CPL ON 
	dbo.CHQ_EMI.CD_EMP = dbo.CHQ_LANC_CPL.CD_EMP AND 
	dbo.CHQ_EMI.CD_EMI = dbo.CHQ_LANC_CPL.CD_EMI ON 
    dbo.CHQ_LANC_CHQ_LANC_CPL.CD_EMP = dbo.CHQ_LANC_CPL.CD_EMP AND 
    dbo.CHQ_LANC_CHQ_LANC_CPL.CD_CHQ = dbo.CHQ_LANC_CPL.CD_CHQ
	LEFT JOIN dbo.BC_PRACA_COMPENSACAO ON 
	dbo.BC_PRACA_COMPENSACAO.CD_COMP_CHQ = dbo.CHQ_LANC_CPL.COMP
	LEFT OUTER JOIN BC_CONTAS C ON
	CHQ_LANC_CPL.CD_EMP = C.CD_EMP AND
	CHQ_LANC_CPL.CD_CNT = C.CD_CNT
ORDER BY 
	dbo.CHQ_LANC_CPL.CD_CHQ


