Retrieving Nth Record | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Retrieving Nth Record


Hi All,
I am writing a procedure to retrieve a record from the table by passing record position.
The procedure should take record number as a parameter and it should return correspond record. Thank You All, With Regards Aruna Mathew
See if this helps:http://www.sql-server-performance.com/q&a124.asp
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterst�tze PASS Deutschland e.V. http://www.sqlpass.de)
Select min(col) from
(
Select top N col from yourTable order by col DESC — replace N by value
) T
Madhivanan Failing to plan is Planning to fail
Note however, that on SQL Server 2000 you cannot parameterise the TOP clause. So, if you need that variable, you cannot use this without dynamic SQL. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterst�tze PASS Deutschland e.V. http://www.sqlpass.de)
Well. If you dont want to use Dynamic SQL, the only way is to make use of RowCount
declare @n int
set @n=3 declare @t table(i int)
set rowcount @n Insert into @t
Select col from yourTable order by col DESC select min(i) as value from yourTable set rowcount 0
Madhivanan Failing to plan is Planning to fail
]]>