Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 7th, 2004, 09:10 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to gmoney060 Send a message via MSN to gmoney060
Default Selecting a Random Recordset

How would I go about selecting a random recordset from a database? I look on a lot of website, and just cant find anything... Any help would be great!

  #2 (permalink)  
Old October 7th, 2004, 09:38 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

???

AND

sql = "SELECT someField FROM sometable WHERE someVariable <> someOterVariable;"

comes to mind, could you elaborate a little more?

Wind is your friend
Matt
  #3 (permalink)  
Old October 7th, 2004, 09:39 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Hmmmm,
Not sure if there is any method for this in MS SQL, but the SQL forums may be able to help with that.
If I was to do this in ASP I would probably load an array with all the primary keys in the table.
Then randomly select the array index.
This is my fisrt though on this, others may have better way.

Or count the records, then randomly select an int between 1 and the count and iterate through the key recordset the random number of times, then that is your random PK.

Basically the same just skips the array.

Rod



======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
  #4 (permalink)  
Old October 7th, 2004, 09:41 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Of course you could select one or many random array indexes or random count values.


======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
  #5 (permalink)  
Old October 7th, 2004, 10:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:selecting a random recordset from a database
Can you explain a bit more on this.

_________________________
- Vijay G
Strive for Perfection
  #6 (permalink)  
Old October 8th, 2004, 03:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

It really depends on which db you're using.

In SQL Server you can do it easily using the NEWID() function:
select top <<number>> * from <<yourtable>> order by newid()

Access is a bit trickier, but can be done using the Rnd() function,
see http://www.adopenstatic.com/faq/RandomRecord.asp


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random recordset kumiko SQL Server 2005 3 March 8th, 2008 12:03 PM
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.