Hallo,

Il 08/03/2016 20.36, setysvar [email protected] [firebird-support] ha 
scritto:
> This will not work properly if more than one row of DC are joined to 
> the same DT (but then your ORDER BY isn't 100% deterministic). If you 
> change the ordering of your query, you also have to change the 
> subselect (e.g. if you add DESC you have to change from > to <). If 
> this doesn't fit, is too slow or too difficult to understand, I'd 
> recommend EXECUTE BLOCK (as Sean already wrote). HTH,

Thank You, the query suggested works but because of the primary index of 
DOC_TESTA the value calculated of SALDO is not compliant with the result 
of the rows of the query.

I solved by creating a stored procedure like this:

AS
BEGIN
   SALDO = 0;

   FOR SELECT
     DT.DATA,
     DT.DOCUMENTO_ID,
     DT.NUMERO,
     DT.SERIE,
     DC.CARICO,
     DC.SCARICO,
     DC.CARICO - DC.SCARICO + :SALDO,
   from
     DOC_TESTA DT
     JOIN DOC_CORPO DC on DT.ID = DC.DOC_TESTA_ID
   WHERE
     DC.ARTICOLO_ID = :ID
   ORDER BY
     DT.DATA,
     DT.DOCUMENTO_ID,
     DT.NUMERO,
     DT.SERIE
   INTO
     :DATADOCUMENTO,
     :DOCUMENTO_ID,
     :NUMERO,
     :SERIE,
     :CARICO,
     :SCARICO,
     :SALDO,

   DO SUSPEND;
END^

Thanks to all :)
-- 

Luigi Siciliano
--------------------------



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

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

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

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:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

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

Reply via email to