retrieve specific range of rows in a SQL Server table(检索 SQL Server 表中特定范围的行)
问题描述
我有一个像 (OrderID [uniqueidentifier], OrderDeciption [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.
提前致谢,乔治
推荐答案
您可以在 TSQL(2005 年以后)中使用 ROW_NUMBER
来执行此操作:
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-to-SQL 等:
Or with LINQ-to-SQL etc:
var qry = ctx.Table.Skip(50).Take(50); // or similar
这篇关于检索 SQL Server 表中特定范围的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检索 SQL Server 表中特定范围的行


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01