Subject RE: [firebird-support] How to use rand()?
Author Svein Erling Tysvær
Why not simply

SELECT FIRST 1 skip (:num) FORTUNE

(and then do the rest as Nick suggests)

rather than selecting that many fortunes?

HTH,
Set

-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Nick Upson
Sent: 7. desember 2007 08:11
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] How to use rand()?

you can do something like this

SET TERM ^ ;
ALTER PROCEDURE GET_RANDOM_FORTUNE
RETURNS (
FORTUNE Varchar(1000) )
AS
num integer;
BEGIN

SELECT count(*)
FROM FORTUNE
INTO :num;

num = rand() * num;

for SELECT FIRST (:num) FORTUNE
FROM FORTUNE
ORDER BY fortune
INTO :FORTUNE;
do
begin
end
SUSPEND;

END^
SET TERM ; ^