
I have read articles in the past that show how to randomize a ColdFusion query once it’s been retrieved from the database. There are probably times when there is a need to do this. However, a more efficient way is to allow the database to handle it before it is even handed to ColdFusion.
Here is an example using SQL Server:
Select
adID, adLink, adImage, newid() as randomNumber
From
Ads
Order by
randomNumber
Short and simple
UPDATED 2/19/2008
See Jason’s note in the comments saying you can change it to the following:
<b>
Select
adID, adLink, adImage
From
Ads
Order by
newid()</b>
Vince Collins
February 19, 2008 at 11:38 am
I’m sure you kow this but you could shorten it even more by just ordering by newid()
SELECT adID, adLink, adImage, FROM Ads ORDER BY newid()
February 19, 2008 at 11:57 am
Thanks Jason,
Actually, I didn’t know that thanks!
Has that always been a feature?