Randomize Recordset Using SQL

SQLServer

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>

SQL Server Express, ColdFusion setup on Vista

I just installed SQL Server Express 2005 on my newly purchased Vista Home Premium laptop. I’m running CF8 (awesome) and installed it with IIS which is what my servers run.

So, why wasn’t I able to set up a datasource within Coldfusion’s administration?

Matt Woodward’s excellent post got me close but for some reason my particular issue didn’t work. I noticed my IPAll TCP Dynamic Ports was something like 46987 and nothing was in my TCP Port setting…blank. It’s not apparent by looking at it but these fields are editable (is that a word?).

So after trying everything that Matt suggested, I deleted the 46987 port (yours will most likely be different), and I just typed in a port (1433) into the TCP Port option. I then restarted the SQL Server instance and tada! I am up and running.

Thanks Matt for getting me close. I hope this helps others.