Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting 14 random records
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01382524
Message ID:
01416780
Views:
60
>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

In my case the first returned 0 rows and for 100 rows it returned 265 records.

http://msdn.microsoft.com/en-us/library/ms189108.aspx
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform