Subject | Re: [firebird-support] why I not get first row in procedure |
---|---|
Author | Tomasz Tyrakowski |
Post date | 2017-09-01T10:21:17Z |
On 01.09.2017 at 11:34, Luigi Siciliano luigisic@...
[firebird-support] wrote:
basically have something like this in your procedure:
for select ... do
for select ... do
suspend
If the outer select doesn't return any rows, the inner one isn't
executed at all, and suspend never gets hit.
Similarly, if the outer select returns rows, but the inner one doesn't,
suspend never gets hit as well.
If that's not what you intended, you're probably missing some begins/ends.
Otherwise, make sure you provide correct results from the outer query as
parameters in the inner query.
saluti dalla Polonia
Tomasz
--
__--==============================--__
__--== Tomasz Tyrakowski ==--__
__--== SOL-SYSTEM ==--__
__--== http://www.sol-system.pl ==--__
__--==============================--__
[firebird-support] wrote:
> Hallo,That's a bit too much to analyze in detail, but just a suggestion. You
>
> why I not get first row in this procedure:
>
> SET TERM ^ ;
> RECREATE PROCEDURE ESTRATTO_CONTO_prova (
> CONTO Char(5),
> CLIENTE Smallint,
> DATADAL DATE,
> DATAAL date )
> RETURNS (
> ID Integer,
> DATA_REGISTRAZIONE Date,
> CAUSALE_ID Char(3),
> DATA_DOCUMENTO Date,
> NUMERO_DOCUMENTO Varchar(20),
> DESCRIZIONE_TESTA Varchar(120),
> DOC_TESTA_ID Integer,
> CONTO_ID Char(5),
> CLIFOR_ID Smallint,
> DARE CURRENCY_D,
> AVERE CURRENCY_D,
> SALDO CURRENCY_D,
> DESCRIZIONE_CORPO Varchar(120),
> PARTITA Integer,
> SCADENZA Date,
> DENOMINAZIONE Varchar(60),
> CAUSALE_DESCRIZIONE Varchar(80),
> CONTO_DESCRIZIONE Varchar(60) )
> AS
> DECLARE VARIABLE SOMMA float;
> BEGIN
>
> SALDO = 0;
>
> FOR SELECT
> 0, /* PNT.ID, */
> :DATADAL, /* PNT.DATA_REGISTRAZIONE, */
> NULL, /* PNT.CAUSALE_ID, */
> :DATADAL, /* PNT.DATA_DOCUMENTO, */
> NULL, /* PNT.NUMERO_DOCUMENTO, */
> NULL, /* PNT.DESCRIZIONE, */
> null, /* PNT.DOC_TESTA_ID, */
> null, /* PNC.CONTO_ID, */
> null, /* IIF (PNC.CLIENTE_ID IS NOT NULL,
> PNC.CLIENTE_ID, PNC.FORNITORE_ID) AS "CLIFOR_ID", */
> COALESCE(SUM(PNC.DARE), 0),
> COALESCE(SUM(PNC.AVERE), 0),
> COALESCE(SUM(PNC.DARE - PNC.AVERE), 0) + :SALDO,
> 'Riporto...', /* PNC.DESCRIZIONE, */
> NULL, /* PNC.PARTITA, */
> NULL, /* PNC.SCADENZA, */
> NULL, /* IIF (PNC.CLIENTE_ID IS NOT NULL,
> C.DENOMINAZIONE, F.DENOMINAZIONE) as DENOMINAZIONE, */
> NULL, /* TC.DESCRIZIONE, */
> NULL /* PDC.DESCRIZIONE */
> from
> PN_TESTA PNT
> JOIN PN_CORPO PNC on PNT.ID = PNC.PN_TESTA_ID
> LEFT JOIN CLIENTI C ON PNC.CLIENTE_ID = C.ID
> LEFT JOIN FORNITORI F ON PNC.FORNITORE_ID = F.ID
> LEFT JOIN TIPO_CAUSALI TC ON PNT.CAUSALE_ID = TC.ID
> LEFT JOIN PIANO_DEI_CONTI PDC ON PNC.CONTO_ID = PDC.ID
> WHERE
> PNC.CONTO_ID = :CONTO
> AND (((PNC.CLIENTE_ID IS NULL) AND (PNC.FORNITORE_ID IS NULL)) OR
> (IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
> PNC.FORNITORE_ID) = :CLIENTE))
> AND DATA_REGISTRAZIONE < :DATADAL
> INTO
> :ID,
> :DATA_REGISTRAZIONE,
> :CAUSALE_ID,
> :DATA_DOCUMENTO,
> :NUMERO_DOCUMENTO,
> :DESCRIZIONE_TESTA,
> :DOC_TESTA_ID,
> :CONTO_ID,
> :CLIFOR_ID,
> :DARE,
> :AVERE,
> :SALDO,
> :DESCRIZIONE_CORPO,
> :PARTITA,
> :SCADENZA,
> :DENOMINAZIONE,
> :CAUSALE_DESCRIZIONE,
> :CONTO_DESCRIZIONE
>
> DO
> FOR SELECT
> PNT.ID,
> PNT.DATA_REGISTRAZIONE,
> PNT.CAUSALE_ID,
> PNT.DATA_DOCUMENTO,
> PNT.NUMERO_DOCUMENTO,
> PNT.DESCRIZIONE,
> PNT.DOC_TESTA_ID,
> PNC.CONTO_ID,
> IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID, PNC.FORNITORE_ID)
> AS "CLIFOR_ID",
> PNC.DARE,
> PNC.AVERE,
> PNC.DARE - PNC.AVERE + :SALDO,
> PNC.DESCRIZIONE,
> PNC.PARTITA,
> PNC.SCADENZA,
> IIF (PNC.CLIENTE_ID IS NOT NULL, C.DENOMINAZIONE, F.DENOMINAZIONE)
> as DENOMINAZIONE,
> TC.DESCRIZIONE,
> PDC.DESCRIZIONE
> from
> PN_TESTA PNT
> JOIN PN_CORPO PNC on PNT.ID = PNC.PN_TESTA_ID
> LEFT JOIN CLIENTI C ON PNC.CLIENTE_ID = C.ID
> LEFT JOIN FORNITORI F ON PNC.FORNITORE_ID = F.ID
> LEFT JOIN TIPO_CAUSALI TC ON PNT.CAUSALE_ID = TC.ID
> LEFT JOIN PIANO_DEI_CONTI PDC ON PNC.CONTO_ID = PDC.ID
> WHERE
> PNC.CONTO_ID = :CONTO
> AND (((PNC.CLIENTE_ID IS NULL) AND (PNC.FORNITORE_ID IS NULL)) OR
> (IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
> PNC.FORNITORE_ID) = :CLIENTE))
> AND PNT.DATA_REGISTRAZIONE >= :DATADAL
> AND PNT.DATA_REGISTRAZIONE <= :DATAAL
> ORDER BY
> PNT.DATA_REGISTRAZIONE,
> PNT.ID,
> PNT.CAUSALE_ID,
> PNT.DATA_DOCUMENTO,
> PNT.NUMERO_DOCUMENTO
> INTO
> :ID,
> :DATA_REGISTRAZIONE,
> :CAUSALE_ID,
> :DATA_DOCUMENTO,
> :NUMERO_DOCUMENTO,
> :DESCRIZIONE_TESTA,
> :DOC_TESTA_ID,
> :CONTO_ID,
> :CLIFOR_ID,
> :DARE,
> :AVERE,
> :SALDO,
> :DESCRIZIONE_CORPO,
> :PARTITA,
> :SCADENZA,
> :DENOMINAZIONE,
> :CAUSALE_DESCRIZIONE,
> :CONTO_DESCRIZIONE
>
> DO SUSPEND;
> END^
> SET TERM ; ^
>
> If I run the select separately I obtain the right result per select.
>
> Thanks.
>
basically have something like this in your procedure:
for select ... do
for select ... do
suspend
If the outer select doesn't return any rows, the inner one isn't
executed at all, and suspend never gets hit.
Similarly, if the outer select returns rows, but the inner one doesn't,
suspend never gets hit as well.
If that's not what you intended, you're probably missing some begins/ends.
Otherwise, make sure you provide correct results from the outer query as
parameters in the inner query.
saluti dalla Polonia
Tomasz
--
__--==============================--__
__--== Tomasz Tyrakowski ==--__
__--== SOL-SYSTEM ==--__
__--== http://www.sol-system.pl ==--__
__--==============================--__