How to Display First 10 Records only from a Result set in Sql Server 2005?

How to display first 10 records from a result set?

Here I used CTE (Common Table Expression), and Row_Number() function in Sql Server 2005.

USE AdventureWorks;
WITH OrderedOrders AS
(SELECT ROW_NUMBER() OVER (order by OrderDate)as RowNumber,*
FROM Sales.SalesOrderHeader )

FROM OrderedOrders
WHERE RowNumber <= 10

No comments: