Wednesday, 31 July 2013

Finding the 10th record in sql table


WITH NthRowCTE AS
(
    SELECT
        ROW_NUMBER() OVER (ORDER BY primarykeyfield) AS RNum
        , *
    FROM tablename
)
SELECT * FROM NthRowCTE WHERE RNum = 10
GO

-----------------------------------------------


select

* from
(
SELECT ROW_NUMBER() OVER (ORDER BY Primaryfieldcolumn) AS tablefield1, tablefield2, tablefield3
FROM Tablename
) T1

where T1.RowNumber=10

No comments:

Post a Comment