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!

Selecting random fields from columns 1

Status
Not open for further replies.

d44

MIS
May 30, 2002
17
GB
I have a table with customers records (tbl_customers) and I am wanting to randomly pick around 1500 records from a list of 5000.The fields are pretty simple....'Forename','Surname','Address' etc.

I could at the very worst just pick lots of 100 or so at a time and put into a new db, but was hoping to be able to use some random function, but wasnt sure how.
 
If you want to select 1500 records at random, this
will do it:

SELECT TOP 1500 fieldlist
FROM yourtable
ORDER BY RND(somenumericfield);

where 'fieldlist' is the list of fields you want
'yourtable' is of course your table
'somenumericfield' is some numeric field in your table
(doesn't have to be in fieldlist)

If you don't have a numeric field in the table, you
can cheat by using RND(LENGTH(somenonnumericfield))

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top