Pular para o conteúdo

Fóruns SQL e PL/SQL Ajuda SQL Ajuda SQL

#87744
Miro
Participante

    vc tem como montar um exemplo com 5 chamadas ????
    DECLARE

    ????????

    BEGIN

    select

    sum (case when(r034fun.datadm <= (DATE) and exists(select 1
    from vetorh.r038hfi
    where r038hfi.numemp = r034fun.numemp
    and r038hfi.tipcol = r034fun.tipcol
    and r038hfi.numcad = r034fun.numcad
    and r038hfi.datalt <= (DATE))
    and not exists (select 1

      from vetorh.r038afa 
         where r038afa.numemp = r034fun.numemp 
             and r038afa.tipcol = r034fun.tipcol 
               and r038afa.numcad = r034fun.numcad 
                 and r038afa.datafa = (select max(r038afa.datafa) 
    
      from vetorh.r038afa, vetorh.r010sit 
         where r038afa.numemp = r034fun.numemp 
             and r038afa.tipcol = r034fun.tipcol 
               and r038afa.numcad = r034fun.numcad 
                 and r038afa.datafa &lt;= (DATE) 
                   and r038afa.sitafa = r010sit.codsit 
                     and r010sit.tipsit = 7))
                       and r038hsa.datalt = (select max (datalt) 
    
      from vetorh.r038hsa tab3 
         where tab3.numemp = r038hsa.numemp
             and tab3.tipcol = r038hsa.tipcol 
               and tab3.numcad = r038hsa.numcad 
                 and tab3.datalt &lt;= DATE)
                   and r038hsa.valsal = (select max (valsal) 
    
      from vetorh.r038hsa tab4 
         where tab4.numemp = r038hsa.numemp 
             and tab4.tipcol = r038hsa.tipcol 
               and tab4.numcad = r038hsa.numcad 
                 and tab4.datalt &lt;= DATE))
    
      then (r038hsa.valsal) end)
    
      from vetorh.r034fun,
           vetorh.r016hie,
           vetorh.r010sit,
           vetorh.r038hsa,
           vetorh.r016orn
    
         where r034fun.sitafa = r010sit.codsit 
             and r034fun.taborg = r016orn.taborg 
               and r034fun.numloc = r016orn.numloc 
                 and r016hie.taborg = r016orn.taborg 
                   and r016hie.numloc = r016orn.numloc 
                     and r038hsa.numemp = r034fun.numemp 
                       and r038hsa.tipcol = r034fun.tipcol 
                         and r038hsa.numcad = r034fun.numcad 
                           and r034fun.numemp in (1,2) 
                             and r034fun.tipcol = 1
                               and r034fun.tipcon = 1
    

    END;

    [quote="Ishii":4mq9em0q]Olá,

    Melhor fazer uma procedure então, pois somente no script do SQL isso seria melhor ser chamado 5 vezes….

    []s Ishii[/quote]