检索行的具体范围在SQL Server表 [英] retrieve specific range of rows in a SQL Server table

查看:114
本文介绍了检索行的具体范围在SQL Server表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样(的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

这篇关于检索行的具体范围在SQL Server表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆