<!--- Here is a very clean and fast way to select a random row in a
table with a Transact SQL Scroll Cursor: --->
<cfquery name="randomRecord" datasource="#request.inet.dsSQL#">
DECLARE random_cursor SCROLL CURSOR FOR
SELECT * FROM Users
ORDER BY Login
DECLARE @randRow integer
SELECT @randRow = (CEILING(RAND() * (SELECT COUNT(login) FROM
Users)))
OPEN random_cursor
-- Perform the random fetch.
FETCH ABSOLUTE @randRow FROM random_cursor
CLOSE random_cursor
DEALLOCATE random_cursor
</cfquery>
<cfdump var="#randomRecord#">
Ryan Duckworth
Macromedia ColdFusion Certified Professional
Uhlig Communications
10983 Granada Lane
Overland Park, KS 66211
(913) 754-4272
-----Original Message-----
From: Damien McKenna [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 26, 2004 4:59 PM
To: CF-Talk
Subject: Re: Returning Random Records
Barney Boisvert wrote:
>SELECT TOP 1 ...
>FROM ...
>WHERE ...
>ORDER BY rand()
>
Sheer genius! Thank you Barney!
--
*Damien McKenna* - Web Developer - [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
The Limu Company - http://www.thelimucompany.com/ - 407-804-1014
"Nothing endures but change." - Heraclitus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Purchase from House of Fusion, a Macromedia Authorized Affiliate and support the CF
community.
http://www.houseoffusion.com/banners/view.cfm?bannerid=37
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:182705
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54