Subject Re: random row select
Author Adam
--- In firebird-support@yahoogroups.com, "Yosvany Llerena Rodríguez"
<yosvanyllr@...> wrote:
>
> Hi all.
>
> I'm tryin to create and stored procedure to select a random row from a
> table, of curse in where clasusle i have an integer field. I means
> random between 1 and the max of this field.
>

You will need to find/write a UDF function to generate a random
number. If your source table is fixed, then the procedure is pretty
simple.

CREATE PROCEDURE FOO
RETURNS
(
BAR INTEGER
)
AS
DECLARE VARIABLE RND INTEGER;
BEGIN
RND = RAND(100);

FOR SELECT BAR
FROM MYTABLE
WHERE ID = :RND
INTO :BAR
DO
BEGIN
SUSPEND;
END
END
^

SELECT BAR
FROM FOO;

Note that a lot of random number generators are based on the internal
clock, and so if you include a call to the SP in a tight loop you may
get the same row several times.

Adam