Select a.cod_cliente, c.num_doc_ref from cxc_enc_pago_nota a, cxc_documento b, cxc_det_pago_nota c, gen_cliente d where a.cod_cia='001' and a.estado='A' and a.tip_doc=b.tip_doc and c.cod_cia='001' and d.cod_cia = '001' and a.cod_cliente = d.cod_cliente and c.sucursal=a.sucursal and a.tip_doc=c.tip_doc and a.num_doc=c.num_doc and a.tip_doc_ref is null and trunc(a.fec_doc) between to_date('01/08/2006', 'dd/mm/yyyy') and to_date('30/12/2006', 'dd/mm/yyyy') And A.LINEA = '001' AND A.COD_CLIENTE = '001' union all Select a.cod_cliente, null num_doc_ref from cxc_enc_movimiento a, cxc_documento b, gen_cliente d where a.cod_cia='001' and d.cod_cia = '001' and a.cod_cliente = d.cod_cliente and a.estado='A' and a.tip_doc=b.tip_doc and a.mon_saldo>0 And A.LINEA = '001' AND A.COD_CLIENTE = '001' Order by origen,fec_doc