Subject Re: [firebird-support] Sql
Author Helen Borrie
At 04:58 AM 23/12/2004 +0000, you wrote:


>Hello
>
> Fb 1.5.1
>
> I have a table currently loaded
> with 300,000 rows .
>
> //here is the meta
>
> CREATE TABLE FDET (
> RNO INTEGER
>, EPOCH INTEGER
>, MSE DECIMAL ( 18, 10 )
>, TRAINTIME TIMESTAMP
>)
>
> I would like to have a query which returns
> every 1000 row , so the resultset would have
> 300 records.
>
> The table is sorted on rno desc .
>
> How would the sql look like ?

You can't do this with a single SQL statement. You can do it with a stored
procedure though:
SET TERM ^;
CREATE PROCEDURE SAMPLING (SAMPLING INTEGER)
RETURNS (
RNO INTEGER,
EPOCH INTEGER,
MSE DECIMAL ( 18, 10 ),
TRAINTIME timestamp)
AS
DECLARE TICKER INTEGER;
BEGIN
TICKER = 0;
FOR SELECT
RNO,
EPOCH,
MSE,
TRAINTIME
FROM FDET
ORDER BY TRAINTIME DESC /* Whatever you need to order by */
INTO
:RNO,
:EPOCH,
:MSE,
:TRAINTIME
DO
BEGIN
TICKER = TICKER + 1;
IF (TICKER = SAMPLING) THEN
BEGIN
SUSPEND;
TICKER = 0;
END
END
END ^

From your application:

SQL: SELECT * FROM SAMPLING(1000)

./hb