Subject | Re: [firebird-support] select every nth row |
---|---|
Author | masotti |
Post date | 2009-04-22T08:30:01Z |
Hi Ron,
Ron Phelps ha scritto:
context functions:
select * from (
select
iif ( RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') is null,
RDB$SET_CONTEXT('USER_TRANSACTION', 'CNT_RECS', '0' ),
RDB$SET_CONTEXT(
'USER_TRANSACTION',
'CNT_RECS',
cast(cast(RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') as
BIGINT)+1 as varchar(80))
)
) settings,
iif ( RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') is null,
0,
cast(RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') as BIGINT ) + 1
) numrec,
ll.ANNO, ll.FACOLTA, ll.PERIODO, ll.PROTOCOLLO,
ll.CORSO, ll.INSEGNAMENTO, ll.DATA_LETTURA, ll.ETA, ll.PRIMASCH
from LETTURE_STORICO ll
) as ct1 (
settings, numrec, anno, facolta, periodo, protocollo, corso, insegnamento,
data_lettura, eta, primascheda
)
-- where mod ( ct1.numrec, 50 ) = 0 -- Why this doesn't work?
and this returns all rows, and numrec colum contains every next number.
So, when I added where part, that is supposed to filter very 50 record
"after" result set is generated, that doesn't work: I've have only first
record after committing, and null record set when retrying.
Seems that RDB$GET / RDB$SET functions are applied "after" filtering
result set.
Maybe some one has a better idea, otherways only choice is STORED
PROCEDURE or EXECUTE BLOCK
Ciao.
Mimmo.
Ron Phelps ha scritto:
> Have a database with a lot of data. To simplify plotting I would like toI read now that you want a single select statement, so tried using user
> "filter" every nth row. Is there a way using a select statement to
> accomplish this?
context functions:
select * from (
select
iif ( RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') is null,
RDB$SET_CONTEXT('USER_TRANSACTION', 'CNT_RECS', '0' ),
RDB$SET_CONTEXT(
'USER_TRANSACTION',
'CNT_RECS',
cast(cast(RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') as
BIGINT)+1 as varchar(80))
)
) settings,
iif ( RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') is null,
0,
cast(RDB$GET_CONTEXT('USER_TRANSACTION', 'CNT_RECS') as BIGINT ) + 1
) numrec,
ll.ANNO, ll.FACOLTA, ll.PERIODO, ll.PROTOCOLLO,
ll.CORSO, ll.INSEGNAMENTO, ll.DATA_LETTURA, ll.ETA, ll.PRIMASCH
from LETTURE_STORICO ll
) as ct1 (
settings, numrec, anno, facolta, periodo, protocollo, corso, insegnamento,
data_lettura, eta, primascheda
)
-- where mod ( ct1.numrec, 50 ) = 0 -- Why this doesn't work?
and this returns all rows, and numrec colum contains every next number.
So, when I added where part, that is supposed to filter very 50 record
"after" result set is generated, that doesn't work: I've have only first
record after committing, and null record set when retrying.
Seems that RDB$GET / RDB$SET functions are applied "after" filtering
result set.
Maybe some one has a better idea, otherways only choice is STORED
PROCEDURE or EXECUTE BLOCK
Ciao.
Mimmo.