SELECT TOP 1 * FROM (SELECT TOP 2 * FROM TABLENAME ORDER BY COLUMNNAME DESC) A ORDER BY COLUMNNAME ASC
This will show the second highest record. I am assuming that the Field COLUMNNAME is what you are actually refering as recordID.
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
The idea is to obtain a query with all lines numbered. so, in that moment you can access any record you want writing where Number=2000
Steps:
1. a functions that receives n and returns n=n+1
2. obtain a data set with order number:
select function(n) as Number, field1,field2 from MyTable order by.... what you want
3. select x.Field1,x.field2 from (select function(n) as Number, field1,field2 from MyTable order by.... what you want ) as x where x.Number=5000.
Hope it helped
Daniela
******
I would love to change the world, but they won't give me the source code
If you are just going to look at the first record then why not do just this
PHP Code:
SELECT TOP 1 * FROM table
WHERE .........
ORDER BY field DESC
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
I said I want the n-th record (order by field), n is large, but not the total !!!
not the last record order by field or max(field) record !!
For example, if a database contains 400000000 records
and the query produces below records from R1 to Rn
( order by field ) , there n large than 1000000 and less than 4000000000
I said I want the n-th record (order by field), n is large, but not the total !!!
not the last record order by field or max(field) record !!
For example, if a database contains 400000000 records
and the query produces below records from R1 to Rn
( order by field ) , there n large than 1000000 and less than 4000000000
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
declare @nr1 int
declare @nr2 int
set @nr1=2
set @nr2=5
--
select * from
(SELECT ROW_NUMBER () OVER ( ORDER BY col1) AS rowNum,col1, col2
FROM tbl ) as A
where A.rowNum between @nr1 and @nr2
order by A.col2
So, if your @nr1 and @nr2 (sent as parametyers to stored proc) have both the same value, returns 1 record, else more records, between @nr1 and @nr2
Hope it helped
Daniela
******
I would love to change the world, but they won't give me the source code
Bookmarks