Subject Re: [ib-support] SQL Language item
Author Helen Borrie
At 12:35 PM 05-09-01 +0000, you wrote:
>Hi all.
>
>As You can see, better than me, below I have a snip from a procedure:
>
>select count(*) from v_avanzamento_pratica where
> ( datagara between :tdal and :tal ) and
> ( ditta_aggiudicataria <> '' )
> into quante_so;
>select count(*) from v_avanzamento_pratica where
> ( datagara between :tdal and :tal ) and
> ( ditta_aggiudicataria <> '' ) and
> ( data_consegna_seggio is not null)
> into consegnate_seggio;
>
>The above count how many records meet the condition:
> ( datagara between :tdal and :tal ) and
> ( ditta_aggiudicataria <> '' )
>
>The second query meet the same condition plus:
> ( data_consegna_seggio is not null )
>
>Please, boy: there is a way to merge the two select?

It might be more efficient to walk the dataset only once and accumulate your "hits" into the variables, instead of walking it twice and having the engine accumulate twice to Count, viz.
...
declare variable v_data_sonsegna_seggio SOMETYPE;
...
begin
quante_so = 0; /* assume this is a return value */
consegnate_seggio = 0; /* assume this is a return value */
v_data_consegna_seggio = 'Something ridiculous';
FOR select data_consegna_seggio from v_avanzamento_pratica
where
( datagara between :tdal and :tal ) and
( ditta_aggiudicataria <> '' )
into v_data_consegna_seggio
do
begin
quante_so = quante_so + 1;
if ( v_data_consegna_seggio <> 'Something ridiculous' ) then
consegnate_seggio = consegnate_seggio + 1;
v_data_consegna_seggio = 'Something ridiculous';
end
end

The reason you can't simply just test the variable for NULL is that NULL isn't a value, so it can't be assigned to a variable. If a value can't be assigned in an iteration of the loop, the variable retains the last non-null value it had.

Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________