views:

182

answers:

2

I have a question about Microsoft SQL Server 2005. How can I delete or select a row from a table that has a specific row number?

+5  A: 

Edit: Modified the code so that it matches more closely to OP's intentions

Declare @RowNum as INT
SET @RowNum = 15 ---Just for example

WITH OrdersRN AS
(
    SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum
          ,OrderID
          ,OrderDate
          ,CustomerID
          ,EmployeeID
      FROM dbo.Orders
)

SELECT * 
  FROM OrdersRN
 WHERE RowNum = @RowNum
 ORDER BY OrderDate
         ,OrderID;
TheTXI
A: 

Check this URL out. Since SQL Server 2005, there is a function called "row_number()" that is what you are looking for.

Pablo Santa Cruz