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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract list of 10 random records from 1000 record table 1

Status
Not open for further replies.

KUZZ

Technical User
Aug 13, 2002
254
GB
How do I extract a list of X random records from a query of Y records, without aplying any filtering criteria other than "randomness". Ideally, I need to export the list of random records to a new table.

Good luck,
Kuzz

"Time spent debating the impossible subtracts from the time during which you
can try to accomplish it."
 
Hi--I searched on 'random' in this forum and got lots of hits. Please try those out first, then let us know if you need any help beyond that.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
paste this code in a module

Code:
Function newguid(Pkname)
Dim TypeLibb
    Set TypeLibb = CreateObject("Scriptlet.TypeLib")
    newguid = Left(TypeLibb.guid, 38)
    'Debug.Print StudentId, Now()
End Function

this will select 10 random records if your table has a primary key

Code:
Select top 10 xxxxx
from tablename
order by newguid(tableprimarykeyname)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top