By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

get 10% random records out of 2000 records

P: n/a
anyone know how can i get a 10% random records out of 2000 records?

2000 is only an example and it will vary anytime.

i want to create a report out of this 10%

thanks in advance
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I don't know the syntax off the top of my head, but how about something like...

Copy the table to a new table (so the original is not irrevocably fragged)
NumRecords = # records in this table
TenPercent = (NumRecords * .1) \ 1 ' Use this as the outer limit of your loop

for K = 1 to TenPercent
RandRecord = a random number between 1 and NumRecords
Go To RandRecord 'go to that row
Pick up relevant data, store to array (or write to a new table)
Delete row #RandRecord 'to prevent this record from future selection
NumRecords = # records in this table 'reset this number to reflect
'remaining number of records
next K

jaYPee <hi******@yahoo.com> wrote in message news:<a7********************************@4ax.com>. ..
anyone know how can i get a 10% random records out of 2000 records?

2000 is only an example and it will vary anytime.

i want to create a report out of this 10%

thanks in advance

Nov 12 '05 #2

P: n/a
Bri
JayPee,

Here is the SQL for a query that will select a random 10% of the records:

SELECT TOP 10 PERCENT MyTable.*, Rnd(aNumericField) AS RandSort
FROM MyTable
ORDER BY Rnd(aNumericField)

Making the RND function use a field in the table as the seed makes the
function get called for each record rather than just once. The field
used as the seed must be numeric and its value should be different for
each record. I usually use the Autonumber PK field that exists in most
tables.
Bri
jaYPee <hi******@yahoo.com> wrote in message
news:<a7********************************@4ax.com>. ..
anyone know how can i get a 10% random records out of 2000 records?

2000 is only an example and it will vary anytime.

i want to create a report out of this 10%

thanks in advance


Nov 12 '05 #3

P: n/a
Thank you very much. this is really what i need.

On Tue, 06 Apr 2004 17:39:24 GMT, Bri <no*@here.com> wrote:
JayPee,

Here is the SQL for a query that will select a random 10% of the records:

SELECT TOP 10 PERCENT MyTable.*, Rnd(aNumericField) AS RandSort
FROM MyTable
ORDER BY Rnd(aNumericField)

Making the RND function use a field in the table as the seed makes the
function get called for each record rather than just once. The field
used as the seed must be numeric and its value should be different for
each record. I usually use the Autonumber PK field that exists in most
tables.
Bri
jaYPee <hi******@yahoo.com> wrote in message
news:<a7********************************@4ax.com> ...
anyone know how can i get a 10% random records out of 2000 records?

2000 is only an example and it will vary anytime.

i want to create a report out of this 10%

thanks in advance


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.