If you are using sqlserver then you could use a stored proc...we use...
CREATE PROCEDURE [dbo].[spr_randomrecord]
AS
DECLARE @Rows int
SET @Rows = SELECT Max(ID) FROM Tables
get_random:
SELECT * FROM Table
WHERE ID = (SELECT CAST((RAND() * @Rows) AS int) + 1)
IF (@@rowcount = 0)
GOTO get_random
GO
You just need to change the relevant table and id names
HTH
-----Original Message-----
From: Chad [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 18, 2002 17:09
To: CF-Talk
Subject: Random SQL statement
I have a table with a Unique ID field and I would like to do a random select
on the table UID.
Basically I want to send the user to a page that displays that random
record.
Does SQL have a random function? I cant find anything in my books. SELECT
rand(ID) FROM table
Or should I select all records from the table and use CF to pick a random
record from the dataset?
Thanks,
Chad
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm