Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting 14 random records
Message
From
22/07/2009 13:26:45
 
 
To
17/02/2009 18:16:33
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01382524
Message ID:
01413751
Views:
62
Michel, unless someone else has posted this....another approach: in SQL 2005 there is a new TABLESAMPLE statement to get a sampling based on # of rows or sampling based on %.
USE AdventureWorks ;
GO
SELECT FirstName, LastName
FROM Person.Contact 
TABLESAMPLE (10 rows) ;
TABLESAMPLE is particularly nice for grabbing a %.....and I'm guessing is faster than using NEWID...however, there are a few gotchas...

- Newid is probably better than this approach, if your sampling includes joins
- If your table is large enough and the sampling is small enough (e.g. 5,000 rows and 10 rows), TABLESAMPLE might not return anything. So you may have to restort to...
USE AdventureWorks ;
GO
SELECT top 10 FirstName, LastName
FROM Person.Contact 
TABLESAMPLE (500 rows) ;
If NEWID works fine for you on large tables, I'd go with NEWID....but if you run into performance or other issues, this might be worth a try
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform