random selection 
Author Message
 random selection
Anybody know how to right a select to grab a random selection of records
from a table. I've done similar in VFP using the random number generator and
ordering with a TOP n clause. SQL's RAND funciton always retruns the same
value. Any ideas?

Thanks



Thu, 26 Feb 2004 00:52:28 GMT
 random selection

Mike,

If you have a table with a numeric value that tends to be different for each
row ... an IDENTITY value is perfect ... try something like:

select top 10 *
from {table}
order by rand (IDENTITYCOL * 1000.0 * datepart(ms, current_timestamp))

If you can guarantee that you will be executing SQL Server on a Win2K
platform, you might also try:

select top 10 *
from {table}
order by NEWID ( )

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.


Quote:
> Anybody know how to right a select to grab a random selection of records
> from a table. I've done similar in VFP using the random number generator
and
> ordering with a TOP n clause. SQL's RAND funciton always retruns the same
> value. Any ideas?

> Thanks



Thu, 26 Feb 2004 01:40:21 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Random selection of rows in a query

2. SQL-->random selections

3. Random selection from table

4. Random selection of numbers

5. Random selection from table

6. random selections??

7. Random selection of resultset rows

8. Random Selection in SQL 2000

9. Random selection

10. random selection?

11. Random Selection

12. Random Selection of 25 Members


 
Powered by phpBB® Forum Software