Link to home
Start Free TrialLog in
Avatar of LizaPaul
LizaPaul

asked on

retrieve fixed records from Interbase

I am using Interbase 6. I want to extract data from an Interbase table using a SELECT statement, but i would like to restrict the number of records extracted to 100. How do I go about doing this with an SQL statement. Or is there any other way to get on with this.
ASKER CERTIFIED SOLUTION
Avatar of vogonPoet
vogonPoet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vogonPoet
vogonPoet

Correction -
this version orders the records properly, inside of the loop. ( assuming that EMP_NO is the correct order )


CREATE PROCEDURE GET_NEXT_RECORDS (
    ASTART_NUM INTEGER,
    ARETURN_COUNT INTEGER)
RETURNS (
    EMP_NO INTEGER,
    FULL_NAME VARCHAR (50))
AS
declare variable nCount INTEGER;
BEGIN
  /* Initialize counter */
  nCount = 0;
 
  /* loop over select statement of ordered rows*/
  FOR SELECT EMP_NO, full_name FROM EMPLOYEE
   where (EMP_NO > :ASTART_NUM )
   order by EMP_NO
   into :EMP_NO, :FULL_NAME DO begin

      /* check counter against desired amount */
      if (nCount < :AReturn_Count ) then begin
     
        /* retun a row and increment counter */
        SUSPEND;
        nCount = nCount + 1;
      end
      else
        /* AReturn_count has been met, terminate */
        Exit;

   end
END
Avatar of LizaPaul

ASKER

Thank you for the answer, it has helped me.