Subject RE: [firebird-support] Re: returning desired amount of results within a stored proc.
Author Martin Dew
Adam.



Thanks for the prompt reply and help. Is select first x supported by IB
5.6 IB 6.02 aswell ?



T.I.A



Martin





________________________________

From: Adam [mailto:s3057043@...]
Sent: 18 February 2005 23:21
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: returning desired amount of results
within a stored proc.




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:
> 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]






________________________________

Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/

* To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
<mailto:firebird-support-unsubscribe@yahoogroups.com?subject=Unsubscribe
>

* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .



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