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

Random samples 1

Status
Not open for further replies.

Paranoia99

Programmer
Apr 16, 2001
6
US
I have a table of invoice numbers that I would like to pull a random sample (of say 1000 invoices) from to evaluate for errors or discrepancies. Is there a way to pull a random sample straight from the SELECT statement?

I know I could make a table with just the list of random invoice numbers first, then do a nested subquery on that table, but I was hoping for something a little more elegant.
 
You could use :
SELECT * form myTable where BETWEEN(recno(),1,1000)

And chage the recno() range if you want to choose another sample.
 
You could use :
SELECT * from myTable where BETWEEN(recno(),1,1000)

And chage the recno() range if you want to choose another sample.
 
You could use :
SELECT * from myTable where BETWEEN(recno(),1,1000)

And change the recno() range if you want to choose another sample.
 
select top 1000 rand() as randnum,* order by 1 desc from mytable

If you want to show how random the numbers really are, you'd need to do something like:

select top 1000 (rand()+.00000000) as randnum,*;
order by 1 desc from mytable

Becase otherwise VFP will round the random number to 2 decimals.

Brian
 
Thanks a lot for the help mgagnon and baltman. Those were exactly the type of responses I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top