Subject | Re: returning desired amount of results within a stored proc. |
---|---|
Author | Adam |
Post date | 2005-02-18T23:21:01Z |
Hi Martin.
A much easier solution is to change your sp to:
CREATE PROCEDURE SP_HISTORY_PRINT
(
LOGURN INTEGER
)
RETURNS
(
URN INTEGER
)
AS
BEGIN
FOR SELECT first 5 l.urn
FROM log l
order by
l.urn descending
INTO :URN
DO
BEGIN
SUSPEND;
END
END
^
Then you don't have to stuff around with the counter. You can also add
the skip 5 if you want to ignore the first 5 records, it just depends
on what you want to do. You may also want to pass in as an input
parameter the number of results to return, which gives you some
flexibility later on.
Adam
--- In firebird-support@yahoogroups.com, "Martin Dew"
<martin.dew@a...> wrote:
A much easier solution is to change your sp to:
CREATE PROCEDURE SP_HISTORY_PRINT
(
LOGURN INTEGER
)
RETURNS
(
URN INTEGER
)
AS
BEGIN
FOR SELECT first 5 l.urn
FROM log l
order by
l.urn descending
INTO :URN
DO
BEGIN
SUSPEND;
END
END
^
Then you don't have to stuff around with the counter. You can also add
the skip 5 if you want to ignore the first 5 records, it just depends
on what you want to do. You may also want to pass in as an input
parameter the number of results to return, which gives you some
flexibility later on.
Adam
--- In firebird-support@yahoogroups.com, "Martin Dew"
<martin.dew@a...> wrote:
> 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]