Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random selection

Status
Not open for further replies.

iainv

Technical User
May 18, 2003
2
GB
How do I use the Rnd function to produce a report that will give me a random 10% of the data enteries in a table?
 
I found the following code at The Access Web site:

'************ Code Begin ***********
'Code courtesy of
'Joe Foster
Function Randomizer () As Integer
Static AlreadyDone As Integer
If AlreadyDone = False Then Randomize : AlreadyDone = True
Randomizer = 0
End Function
'************ Code End *************
Now to get 100 questions picked at random:

select top 100 mytable.* from mytable
where randomizer() = 0
order by rnd(isnull(mytable.question) * 0 + 1)

Your SQL code would have to be modified with your table name and the name of a field with a unique value to select on. Also, the number of records that represents 10% of your table. this value can be done dynamically with code. If you need help with that process just post back and I can help you with that.



Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top