Pular para o conteúdo

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

#87737
Miro
Participante

    Ola, agradeço mas nao entendi muito bem ficaria assim : mas nao rodou

    select

    sum (case when(r034fun.datadm <= ('&&data1,&&data2') 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 <= ('&&data1,&&data2'))
    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;= ('&amp;&amp;data1,&amp;&amp;data2') 
                   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;= '&amp;&amp;data1,&amp;&amp;data2')
                   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;= '&amp;&amp;data1,&amp;&amp;data2'))
    
      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
    

    [quote="Ishii":3uar8khw]Olá,

    Uma alternativa se eu entendi direito é colocar um &data diferente para cada caso. Tipo &data1, &data2, etc que ele vai pedir para cada parâmetro um novo valor, desta forma que esta se eu passar somente um (&data) ele será usado para os outros casos.

    []s Ishii[/quote]