Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written a query which retrieves top 5 records from a table like this

SQL
SELECT Top(5)  Activity, GETUTCDATE() as CurrentDate
    FROM Activities
    WHERE UserID = @uid
    ORDER BY ActivityDate DESC


and on View i am displaying top 5 records and i also have a link of More on clicking of which next 5 records should show,again clicking on that link show next 5 records and so on

I am having confusion on how to write this query ie how to get next 5 records then next 5 and so on
Posted
Comments
Rishikesh_Singh 27-Feb-12 5:10am    
what do you mean by view? Are you saying you have to display it in grid in UI and you have pagination there.
Syed Salman Raza Zaidi 27-Feb-12 5:31am    
no View means MVC view

Use the ROW_NUMBER[^] clause.
 
Share this answer
 
it may help u...

SELECT * FROM (
SELECT TOP 5 -- actually bottom five of the top fifteen (seek 10)
*
FROM
(
SELECT TOP 15
*
FROM
Table
ORDER BY
Field
)
ORDER BY
Field DESC
)
ORDER BY Field -- fix order
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900