Monday, June 22, 2009

Top With Percent in SQL

In SQL percent keyword helps to retrieve %age of records from a table.

Have a look at this sample query, In AdventureWorks database, Sales.SalesOrderHeader contains 31465 records, in the following query we are going to retrieve almost 10% of records

USE AdventureWorks


SELECT top 10 percent * FROM Sales.SalesOrderHeader

This query will return 3147 records

No comments:

Post a Comment