Forums

ASP

This topic is locked

How do I select a random record?

Posted 22 Sep 2006 15:03:08
1
has voted
22 Sep 2006 15:03:08 Nils Satterstrom posted:
I was wondering if anyone knew how to display a random record from a recordset. I am using asp vbsript with an ms access database. I'm thinking it must be a simple SQL statement, but havn't been able to find one.
Thanks
Nils

Replies

Replied 25 Sep 2006 04:38:46
25 Sep 2006 04:38:46 Wim Conix replied:
Hello,

I recently learned this little trick :

ORDER BY NewID()

It works !

Hope this helps,

Wim

Wim Conix
www.image-belle.com
Replied 25 Sep 2006 14:19:39
25 Sep 2006 14:19:39 Nils Satterstrom replied:
Thanks for your help, however I still receive an error that says
"Undefined function 'NewID' in Expression"

Maybe this doens't work with MsAccess

Appreciate your help though
Nils
Replied 25 Sep 2006 14:24:22
25 Sep 2006 14:24:22 Wim Conix replied:
Hello,

That's possible.
I'm working with SQL Server.
If I find solution for Access, I'll let you know.

Wim

Wim Conix
www.image-belle.com
Replied 27 Sep 2006 17:10:19
27 Sep 2006 17:10:19 Vince Baker replied:
according to Microsoft there is no random command for access but here is a link to their solution:

support.microsoft.com/kb/210468/EN-US/

Regards

Vince Baker
<strong>DMX Zone Manager</strong>

[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 15 Oct 2006 22:18:38
15 Oct 2006 22:18:38 micah santos replied:
what if you just simply make a random number?

try to get the recordcount first of your database records, then, use that value for generating random numbers as your basis. so that, you won't exceed from the exact count of your records.

after producing several random numbers, let's say, 5,10,40,58...

then, retrieve these records corresponding to the ID of your random value results.

Reply to this topic