Subject | Re: [firebird-support] Query and problem with nulls |
---|---|
Author | Luigi Siciliano |
Post date | 2018-01-04T15:55:11Z |
Hallo,
Il 04/01/2018 12.39, Dimitry Sibiryakov sd@...
[firebird-support] ha scritto:
SQL> SELECT
CON> DEPOSITO_ID,
CON> RIPORTO,
CON> CARICO,
CON> SCARICO,
CON> RIPORTO + ESISTENZA AS ESISTENZA,
CON> IMPEGNATI,
CON> ORDINATI
CON> FROM
CON> (
CON> SELECT
CON> DT.DEPOSITO_ID,
CON> (SELECT
CON> SUM(DC2.CARICO - DC2.SCARICO)
CON> FROM
CON> DOC_CORPO DC2,
CON> DOC_TESTA DT2
CON> WHERE
CON> DC2.DOC_TESTA_ID = DT2.ID
CON> AND DC2.ARTICOLO_ID = 'CRSSV750'
CON> AND DT2.DATA < '01/01/2018'
CON> ) AS RIPORTO,
CON> SUM(DC.CARICO) as Carico,
CON> SUM(DC.SCARICO) as Scarico,
CON> SUM(DC.CARICO - DC.SCARICO) as ESISTENZA,
CON> SUM(DC.IMPEGNATI) as Impegnati,
CON> SUM(DC.ORDINATI) as Ordinati
CON> FROM
CON> DOC_CORPO DC, DOC_TESTA DT
CON> WHERE
CON> DC.DOC_TESTA_ID = DT.ID
CON> AND DC.ARTICOLO_ID = 'CRSSV750'
CON> AND DT.DATA >= '01/01/2018'
CON> AND DT.DATA <= '12/31/2018'
CON> GROUP BY
CON> DT.DEPOSITO_ID
CON> );
SQL> SELECT
CON> DEPOSITO_ID,
CON> RIPORTO,
CON> CARICO,
CON> SCARICO,
CON> RIPORTO + ESISTENZA AS ESISTENZA,
CON> IMPEGNATI,
CON> ORDINATI
CON> FROM
CON> (
CON> SELECT
CON> DT.DEPOSITO_ID,
CON> (SELECT
CON> SUM(DC2.CARICO - DC2.SCARICO)
CON> FROM
CON> DOC_CORPO DC2,
CON> DOC_TESTA DT2
CON> WHERE
CON> DC2.DOC_TESTA_ID = DT2.ID
CON> AND DC2.ARTICOLO_ID = 'CRSSV750'
CON> AND DT2.DATA < '01/01/2017'
CON> ) AS RIPORTO,
CON> SUM(DC.CARICO) as Carico,
CON> SUM(DC.SCARICO) as Scarico,
CON> SUM(DC.CARICO - DC.SCARICO) as ESISTENZA,
CON> SUM(DC.IMPEGNATI) as Impegnati,
CON> SUM(DC.ORDINATI) as Ordinati
CON> FROM
CON> DOC_CORPO DC, DOC_TESTA DT
CON> WHERE
CON> DC.DOC_TESTA_ID = DT.ID
CON> AND DC.ARTICOLO_ID = 'CRSSV750'
CON> AND DT.DATA >= '01/01/2017'
CON> AND DT.DATA <= '12/31/2017'
CON> GROUP BY
CON> DT.DEPOSITO_ID
CON> );
DEPOSITO_ID RIPORTO CARICO SCAR
ICO ESISTENZA IMPEGNATI ORDINATI
=========== ======================= =======================
====================
=== ======================= ======================= =======================
1 0.0000000000000000 1.000000000000000 0.0000000000000
000 1.000000000000000 0.0000000000000000 0.0000000000000000
As you see:
- if I select between 01/01/2018 and 31/12/2018 the are not rows in DT
- if I select between 01/01/2017 and 31/12/2017 works fine because the
are at least 1 row in DT
Any suggestion?
Thanks.
--
Luigi Siciliano
--------------------------
Il 04/01/2018 12.39, Dimitry Sibiryakov sd@...
[firebird-support] ha scritto:
> Are you sure that your query really returns all nulls and this is not a visual bug inthe log is:
> the tool you run this query in? Show log from isql, please.
SQL> SELECT
CON> DEPOSITO_ID,
CON> RIPORTO,
CON> CARICO,
CON> SCARICO,
CON> RIPORTO + ESISTENZA AS ESISTENZA,
CON> IMPEGNATI,
CON> ORDINATI
CON> FROM
CON> (
CON> SELECT
CON> DT.DEPOSITO_ID,
CON> (SELECT
CON> SUM(DC2.CARICO - DC2.SCARICO)
CON> FROM
CON> DOC_CORPO DC2,
CON> DOC_TESTA DT2
CON> WHERE
CON> DC2.DOC_TESTA_ID = DT2.ID
CON> AND DC2.ARTICOLO_ID = 'CRSSV750'
CON> AND DT2.DATA < '01/01/2018'
CON> ) AS RIPORTO,
CON> SUM(DC.CARICO) as Carico,
CON> SUM(DC.SCARICO) as Scarico,
CON> SUM(DC.CARICO - DC.SCARICO) as ESISTENZA,
CON> SUM(DC.IMPEGNATI) as Impegnati,
CON> SUM(DC.ORDINATI) as Ordinati
CON> FROM
CON> DOC_CORPO DC, DOC_TESTA DT
CON> WHERE
CON> DC.DOC_TESTA_ID = DT.ID
CON> AND DC.ARTICOLO_ID = 'CRSSV750'
CON> AND DT.DATA >= '01/01/2018'
CON> AND DT.DATA <= '12/31/2018'
CON> GROUP BY
CON> DT.DEPOSITO_ID
CON> );
SQL> SELECT
CON> DEPOSITO_ID,
CON> RIPORTO,
CON> CARICO,
CON> SCARICO,
CON> RIPORTO + ESISTENZA AS ESISTENZA,
CON> IMPEGNATI,
CON> ORDINATI
CON> FROM
CON> (
CON> SELECT
CON> DT.DEPOSITO_ID,
CON> (SELECT
CON> SUM(DC2.CARICO - DC2.SCARICO)
CON> FROM
CON> DOC_CORPO DC2,
CON> DOC_TESTA DT2
CON> WHERE
CON> DC2.DOC_TESTA_ID = DT2.ID
CON> AND DC2.ARTICOLO_ID = 'CRSSV750'
CON> AND DT2.DATA < '01/01/2017'
CON> ) AS RIPORTO,
CON> SUM(DC.CARICO) as Carico,
CON> SUM(DC.SCARICO) as Scarico,
CON> SUM(DC.CARICO - DC.SCARICO) as ESISTENZA,
CON> SUM(DC.IMPEGNATI) as Impegnati,
CON> SUM(DC.ORDINATI) as Ordinati
CON> FROM
CON> DOC_CORPO DC, DOC_TESTA DT
CON> WHERE
CON> DC.DOC_TESTA_ID = DT.ID
CON> AND DC.ARTICOLO_ID = 'CRSSV750'
CON> AND DT.DATA >= '01/01/2017'
CON> AND DT.DATA <= '12/31/2017'
CON> GROUP BY
CON> DT.DEPOSITO_ID
CON> );
DEPOSITO_ID RIPORTO CARICO SCAR
ICO ESISTENZA IMPEGNATI ORDINATI
=========== ======================= =======================
====================
=== ======================= ======================= =======================
1 0.0000000000000000 1.000000000000000 0.0000000000000
000 1.000000000000000 0.0000000000000000 0.0000000000000000
As you see:
- if I select between 01/01/2018 and 31/12/2018 the are not rows in DT
- if I select between 01/01/2017 and 31/12/2017 works fine because the
are at least 1 row in DT
Any suggestion?
Thanks.
--
Luigi Siciliano
--------------------------