I need to pull a random record from an autonumber field. It's for a prize for
the lucky winner. :)
I'd thought about creating a ValueList() from the ID field, but then got stuck
in my thinking. What's the best way to accomplish this?
Thanks,
Will
~~~
What DB? With SQL Server 2K, I think the following will work
(untested - going straight from distant memory):
SELECT TOP 1 myfield
FROM mytable
ORDER BY NEWID()
On 3/29/06, Will Tomlinson <[EMAIL PROTECTED]> wrote:
> I need to pull a random record from an autonumber field. It's for a prize for
> What DB? With SQL Server 2K, I think the following will work
> (untested - going straight from distant memory):
I'm sorry - it's Access.
Thanks,
Will
~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:236460
Archive
What DB are you using?
If you are using MS SQL Server you can create a new column in your query and
give it the value of a random number and then sort by that column, then just
take the top record as the winner.
SELECT NEWID() AS Test
FROM MyTable
ORDER BY Test
Just Query Your DB as
Not so easy, then. Try Google-ing "ms access random record" and
you'll get a lot of info about creating seeds, etc. You can go that
direction or return all and select a random record using randRange (
1, queryName.recordcount ).
Again, that's from memory, so you might have to play with it a bit.
I should mention that the latter option - returning everything just to
use one - can have a big performance impact, so be careful with that
one.
On 3/29/06, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> Not so easy, then. Try Google-ing "ms access random record" and
> you'll get a lot of info about
lk
Subject: Pulling a random record from the DB
I need to pull a random record from an autonumber field. It's for a prize
for the lucky winner. :)
I'd thought about creating a ValueList() from the ID field, but then got
stuck in my thinking. What's the best way to accom
: CF-Talk
Subject: Re: Pulling a random record from the DB
I should mention that the latter option - returning everything just to
use one - can have a big performance impact, so be careful with that
one.
On 3/29/06, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> Not so easy, then. Try Googl
://support.microsoft.com/?kbid=210468
..:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
-Original Message-
From: Andy Matthews [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 29, 2006 4:18 PM
To: CF-Talk
Subject: RE: Pulling a random record from the DB
You didn
You could alwys just say F it and manually pick a record.
=]
Oh yeah, where do I sign up and what do I win?
--
Alan Rother
Macromedia Certified Advanced ColdFusion MX 7 Developer
~|
Message: http://www.houseoffusion.com/list
Thanks guys!
These ideas did the trick! :)
Will
~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:236502
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.c
11 matches
Mail list logo