开发者

How to determine order number of an item in sorted table

开发者 https://www.devze.com 2023-01-16 06:45 出处:网络
(continued from Read N consequent items by ActiveRecord) My project is C# and uses CastleProject ActiveRecord on MS SQL Server database.

(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 messa开发者_开发技巧ge 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消