检索行的具体范围在SQL Server表范围、具体、Server、SQL

2023-09-03 00:12:06 作者:余生有你就好

我有这样(的OrderID [唯一标识符],OrderDesciption [NVARCHAR]),我使用的ADO.Net + C#+ VSTS表结构2008 + SQL Server 2008中的表是很大的,我想让客户端给我两个输入端,开始一系列指数和结束范围指标,我将返回表,该表的范围是特定的行(开始一系列指数和结束范围指数之间)。

I have a table structure like (OrderID [uniqueidentifier], OrderDesciption [nvarchar]), I am using ADO.Net + C# + VSTS 2008 + SQL Server 2008. The table is big, and I want to let client give me two inputs, begin range index and end range index, and I will return specific rows of the table which is in the range (between begin range index and end range index).

例如,如果客户端输入我50,100,我想回到第50行,直到第100行。

For example, if the client inputs to me 50, 100, and I want to return the 50th row until the 100th row.

在此先感谢, 乔治

推荐答案

您可以使用 ROW_NUMBER 在TSQL(2005年起),要做到这一点:

You can use ROW_NUMBER in TSQL (2005 onwards) to do this:

SELECT  ID, Foo, Bar
FROM     (SELECT  ROW_NUMBER() OVER (ORDER BY ID ASC) AS Row,
          ID, Foo, Bar
FROM    SomeTable) tmp
WHERE   Row >= 50 AND Row <= 100

或者使用LINQ到SQL等:

Or with LINQ-to-SQL etc:

var qry = ctx.Table.Skip(50).Take(50); // or similar
 
精彩推荐
图片推荐