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

Pick random files from table via query?

Status
Not open for further replies.

Louise99

Technical User
Sep 13, 2004
70
US
I need to pick 20 random files from a table with the only criteria is within a certain month. Can I do this through the Query by example without writing any code?

Thanks!
 
Louise99,
Maybe? You might might be able to use the random number generator. This example uses a combination of a Date/Time field in the table and the current time to create a seed that is feed to the random number generator.
Code:
SELECT TOP 20 KeyField
FROM YourTable
ORDER BY Rnd(Now()-[i]DateTimeField[/i]) DESC;

Everytime I requery I get a different subset of 20 records.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top