Subject Re: RE: RE: [firebird-support] Re: returning desired amount of results within a stored proc.
Author Pavel Menshchikov
Hello Martin,

What was wrong with your original SP? Errors at compilation? Wrong
output?

Try this (it's almost the same procedure as you posted)
-----
CREATE PROCEDURE SP_HISTORY_PRINT (
LOGURN INTEGER /* you don't use it in this version of the SP (maybe
in your real SP you do) */
) RETURNS (
URN INTEGER
) AS
declare variable recordsToGet integer;
declare variable nCount integer;
BEGIN
recordsToGet = 5; /* I'd prefer to pass the value as the SP parameter */
nCount = 0;
FOR
SELECT
l.urn
FROM
log l
order by
l.urn descending /* don't forget to create desc index
on that field */
INTO
:urn
DO BEGIN
SUSPEND;
nCount = nCount + 1;
if (nCount = recordsToGet) then
EXIT;
END
END /* don't forget terminator */
-----


HTH
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com