Subject RE: [firebird-support] returning desired amount of results within a stored proc.
Author Martin Dew
I currently have IB5.6, IB 6.2 and FB 1.5.2 at sites, I need a solution
to enable me to stop returning records after I have a designated amount,
this solution needs to work with all of the IB and FB versions I
currently use. Then only way I can think that will work with all is to
use a counter variable, and an amount of records variable. I cannot seem
to make it exit when I have got my recordsToGet amount.



Can anyone help with the correct syntax to exit and return the records
it has thus far processed for me ?



CREATE PROCEDURE SP_HISTORY_PRINT (

LOGURN INTEGER

) RETURNS (

URN INTEGER

) AS



declare variable recordsToGet integer;

declare variable nCount integer;



BEGIN



recordsToGet = 5;

nCount = 0;

FOR

SELECT

l.urn

FROM

log l

order by

l.urn descending

INTO

:urn

DO BEGIN

nCount = nCount + 1;

if (nCount = recordsToGet) then

EXIT;

SUSPEND;

END

END



T.I.A



Martin



[Non-text portions of this message have been removed]