IF OBJECT_ID('V_CUPOMNAOFISCAL_CHEQUE') IS NOT NULL 
	DROP VIEW V_CUPOMNAOFISCAL_CHEQUE 
GO 

CREATE VIEW V_CUPOMNAOFISCAL_CHEQUE
AS
SELECT	CUPOM.CD_EMP,CUPOM.CD_FILIAL,CUPOM.DT_CUPOM,CUPOM.CD_CX,CUPOM.CD_CTR,CUPOM.NR_COO
	,COALESCE(BC.CD_BC,CHQ.CD_BC_CHQ) AS CD_BC,BC.DS_BC AS NM_BC 
	,CHQ.NR_ORD, CHQ.NR_CHQ, CHQ.ANO_CHQ, CHQ.VL_CHQ AS VLR_CHQ,DT_CUPOM AS DT_EMI,CHQ.DT_VENCTO
	,AG_CHQ, CPF_CGC_EMI AS CGC_EMI, NM_EMI,
	FONE_EMI,NR_CNT_CHQ, AUT_CHQ,0 AS COMP_CHQ
	,C1_CHQ, C2_CHQ,CHQ.SR_CHQ AS C3_CHQ,CMC7_CHQ,MES_ANO_CNT_CHQ
FROM 	PDV_CUPOM_NAO_FISCAL CUPOM
INNER 	JOIN PDV_CUPOM_NAO_FISCAL_CHQS CHQ ON CUPOM.CD_EMP = CHQ.CD_EMP AND CUPOM.CD_FILIAL = CHQ.CD_FILIAL AND CUPOM.CD_CTR = CHQ.CD_CTR
LEFT 	JOIN BC_BANCO BC ON BC.CD_BC = CHQ.CD_BC_CHQ