Tom Forbes wrote:
>
> I need to modify the below query so that my results are still ordered by
> "ClassOfService" (a number between 1 and 4) - BUT, the "CompanyName" needs
> to be displayed in a RANDOM ORDER each time the query is run, rather than
> its current alphabetical order. This will give all companies that
> participate an even advantage of being selected rather than those that
> begin with the first letters of the alphabet.
Usually I do:
SELECT <fields>
FROM <tables>
WHERE <predicates>
ORDER BY
Random()
It might be that your database does not support that because the
Random() function needs to be seeded or else it will generate the same
sequence every time. In that case, seed it with a different random
number for each row. This different random number is best obtained by
taking the primary key (different) and add a number (random).
SELECT <fields>
FROM <tables>
WHERE <predicates>
ORDER BY
Random(PrimaryKey + <cfqueryparam cfsqltype="cf_sql_integer"
value="#RandRange(1,999999)#">)
This might be a little hard on your CPU when you have many records.
Jochem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Get the mailserver that powers this list at http://www.coolfusion.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4