Join two Select

0

I am developing a report in PowerBuilder and would like to know how to merge results from two SQL queries into the report. If I add the function f_block_to_number in the first query and add the invoice table in from, the records multiply in the report so I wanted to leave a query just to bring our number


Ex : 
  Nome  Nosso Numero
  José      007
  José      007
  José      007

I believe this happens because v_request is a View that contains data from the Invoice table.

But I can not make the select direct in the invoice table because it does not have all the data for the report, since the data view has several tables.


select v_arrecadacao.tipo,
       v_arrecadacao.idregiao,
       v_arrecadacao.idbairro,
       v_arrecadacao.idrota,
       v_arrecadacao.sequencia_leit,
       v_arrecadacao.iduc,
       v_arrecadacao.idclasse,
       v_arrecadacao.refaturamento,
       v_arrecadacao.retificado,
       v_arrecadacao.numero_reaviso,
       v_arrecadacao.nome,
       v_arrecadacao.numero_fiscal,
       v_arrecadacao.ano_mes,
       v_arrecadacao.ano_mes_original,
       v_arrecadacao.tipo_calculo,
       v_arrecadacao.data,
       v_arrecadacao.datahora,
v_arrecadacao.empresas_nome, v_arrecadacao.idagente, v_arrecadacao.agentearrecadador_nome, v_arrecadacao.datahora, v_arrecadacao.valor_recebido as valor_recebido, v_arrecadacao.situacao, v_arrecadacao.valor_diferenca,

f_bloqueto_nosso_numero(33,3265,fatura.tipo_calculo,fatura.idcodfatura,fatura.vcto,fatura.iduc,fatura.ano_mes,13000617) as nosso_numero, nvl((select uc.ligado from uc where uc.iduc = v_arrecadacao.iduc),'S') as ligado, nvl((select uc.idmotivodeslig from uc where uc.iduc = v_arrecadacao.iduc),0) as idmotivodeslig

from v_arrecadacao, fatura

where v_arrecadacao.data BETWEEN :pagto_ini AND :pagto_final
and v_arrecadacao.motivo_baixa = 1

UNION

select fatura.iduc, fatura.vcto , fatura.tipo_calculo, fatura.idcodfatura, fatura.ano_mes , f_bloqueto_nosso_numero(33,3265,fatura.tipo_calculo,fatura.idcodfatura,fatura.vcto,fatura.iduc,fatura.ano_mes,13000617) as nosso_numero

from fatura

where fatura.iduc = v_arrecadacao.iduc

    
asked by anonymous 20.05.2014 / 18:36

1 answer

2

To join two queries, the UNION ALL statement is usually used. You just have to make sure that all UNION ALL queries have the same number of columns.

Following reference: link

Hugs,

    
01.08.2014 / 04:09