Board index » delphi » Limiting size of result set

Limiting size of result set

Is there a way with Interbase 6 to limit the size of the Result set e.g.
to 1,000 records?

Todd

--
Todd Cary
Ariste Software
t...@aristesoftware.com

 

Re:Limiting size of result set


Use a stored procedure and pass the number of rows desired as a parmeter.
Run a counter inside your FOR SELECT/DO and exit when the required number of
rows have been returned.

--
Bill
(TeamB cannot answer questions received via email)

Re:Limiting size of result set


Bill -

I am embarrassed to admit that in all of my years of using Interbase I
have never created a Stored Procedure.  Is there an example of what you
suggested?

Todd

P.S. I remember when you attended one of the original Paradox meetings
in San Francisco many years ago!

--
Todd Cary
Ariste Software
Petaluma, CA 94952
t...@aristesoftware.com

Re:Limiting size of result set


Something like the following should work.

SET TERM ^ ;

CREATE PROCEDURE GET_RECS(NUM_RECS INTEGER)
RETURNS
(
CUST_NO INTEGER,
NAME VARCHAR(40)
)
AS
DECLARE VARIABLE I INTEGER
BEGIN
  I = 0
  FOR SELECT CUSTNO, COMPANY FROM CUSTOMER
    ORDER BY TOTAL_SALES DESC
    INTO :CUST_NO, :NAME
  DO
  BEGIN
    I = I + 1;
    IF I > NUM_RECS THEN EXIT;
    SUSPEND;
  END
END^

SET TERM ; ^

--
Bill
(TeamB cannot answer questions received via email)

Other Threads