How to determine order number of an item in sorted table

前提是你 提交于 2019-12-11 12:21:34

问题


(continued from Read N consequent items by ActiveRecord)

My project is C# and uses CastleProject ActiveRecord on MS SQL Server database.

I need to understand the order number of an item from a database, if some sorting criteria applied.

Example: I have a lot of messages in some table, where message has ID, time and text. I'd like to understand which number particular message will have, if I sort messages by time. Next time, I'd like to get order number of the same message when sort by text applied.

Is it possible to achieve with ActiveRecord means or only with stored procedures on SQL Server?


回答1:


You need to use the ROW_NUMBER() function. Check this link:

http://www.singingeels.com/Articles/Pagination_In_SQL_Server_2005.aspx

It works the same for SQL Server 2008, so don't worry.



来源:https://stackoverflow.com/questions/3709707/how-to-determine-order-number-of-an-item-in-sorted-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!