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 表中特定范围的行


- 使用 rss + c# 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01