Tags: , | Categories: Knowledgebase Posted by Ian Blair on 2/27/2011 11:19 AM | Comments (0)

A quick way of selecting a batch of random records from a SQL table is to include the NEWID() function in the WHERE clause. This function generates Windows GUID values and provides for most purposes a resonably random set of results.

Use:
Select top [xx] * from [TABLENAME] where value='sample' order by NEWID()

The above example will return a random sample of xx records with the matching WHERE clause.


Example:
Select top 10 from contact1 where key3='Prospect' order by NEWID()

Comments are closed