question

Murali avatar image
Murali asked

how to find the absolute position of a record

i have a requirement like, in the application i have two buttons called PREV AND NEXT buttons and i am passing a parameter like date. suppose if i give the date as '11/20/2010' on the date it will list out all the rows. suppose from the application if i press PREVIOUS button...it should go to previous record from the current record...if i press NEXT it should go to NEXT record from the current record.
t-sql
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Are you after a single snapshot of the data, and to work your way through it, or are you thinking of an app that checks the database between refreshes?
1 Like 1 ·

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
**EDIT** I see now that what you're actually asking for is ONE record. The procedure will handle that too, pass @pagesize=1. **END EDIT** Untested, but I think this will work. CREATE PROC GetPage(@d date, @page int=1, @pagesize int=10) AS WITH PagingTable AS( SELECT col1, col2, col3, ROW_NUMBER() OVER(ORDER BY col1) As RowNum FROM some_table WHERE some_date_column=@dt) SELECT * FROM PagingTable WHERE RowNum BETWEEN (@page-1)*@pagesize +1 AND @page*@pagesize ORDER BY RowNum
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.