Il 07/03/2016 17.28, Thomas Steinmaurer t...@iblogmanager.com 
[firebird-support] ha scritto:
> Although not that flexible as an ad-hoc query, but perhaps your
> particular use case can be achieved with a selectable stored procedure
> ...

Thank you Thomas, I modified my query like this:

select
    DT.DATA,
   DT.DOCUMENTO_ID,
   DT.NUMERO,
   DT.SERIE,
   DC.CARICO,
   DC.SCARICO,
   SUM(dc2.carico - DC2.SCARICO) AS saldo
from
   DOC_TESTA DT
   JOIN DOC_CORPO DC on DT.ID = DC.DOC_TESTA_ID
   left JOIN DOC_CORPO DC2 ON (DC.DOC_TESTA_ID >= DC2.DOC_TESTA_ID)
                                                        AND 
(DC.ARTICOLO_ID = DC2.ARTICOLO_ID)
WHERE
    DC.ARTICOLO_ID = :ID
GROUP BY
    DATA,
   DOCUMENTO_ID,
   NUMERO,
   SERIE
ORDER BY
    DATA,
   DOCUMENTO_ID,
   NUMERO,
   SERIE

but I have an issue:
if I have a row with CARICO = 0 and SCARICO = 0, SALDO is added or 
subtracted by the number present in last row with
CARICO > 0 or SCARICO > 0

if I add "(AND(DC.CARICO + DC.SCARICO) > 0) IN a LEFT JOIN I obtain 
almost correct result but the rows that contain "CARICO = 0 and SCARICO 
= 0" now contain SALDO = NULL, the others contains correct progressive sum.

What I'm wrong?

Thanks
-- 
<pre>
Luigi Siciliano
--------------------------
</pre>
-- 
<pre>
Luigi Siciliano
--------------------------
</pre>


------------------------------------

------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu.  Try FAQ and other links from the left-side menu there.

Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/ 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/firebird-support/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/firebird-support/join
    (Yahoo! ID required)

<*> To change settings via email:
    firebird-support-dig...@yahoogroups.com 
    firebird-support-fullfeatu...@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    firebird-support-unsubscr...@yahoogroups.com

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/

              • ... 'Leyne, Sean' s...@broadviewsoftware.com [firebird-support]
              • ... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
              • ... Thomas Steinmaurer t...@iblogmanager.com [firebird-support]
              • ... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
              • ... Thomas Steinmaurer t...@iblogmanager.com [firebird-support]
              • ... 'Leyne, Sean' s...@broadviewsoftware.com [firebird-support]
              • ... Lester Caine les...@lsces.co.uk [firebird-support]
              • ... 'Carlos H. Cantu' lis...@warmboot.com.br [firebird-support]
      • Re: [... Thomas Steinmaurer t...@iblogmanager.com [firebird-support]
        • R... 'Leyne, Sean' s...@broadviewsoftware.com [firebird-support]
        • R... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
          • ... r...@graficalc.nl [firebird-support]
            • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
              • ... Rik van Kekem r...@graficalc.nl [firebird-support]
    • Re: [fire... Mark Rotteveel m...@lawinegevaar.nl [firebird-support]
  • Re: [firebird-... setysvar setys...@gmail.com [firebird-support]
    • Re: [fire... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]

Reply via email to