如何获得最高记录和最高记录下方的下一次记录 [英] How to get top records and next time records below the top records

查看:82
本文介绍了如何获得最高记录和最高记录下方的下一次记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的要求是,我有300条记录的"temp"表
如果我给了25个
我想从temp获得1-25条记录,
下次如果我给75
我想从temp获得25-100条记录,
下次如果我给了200
我想要100-300之间的记录
下次如果我给了50
我想要1-50的记录

Hi all,

my requirement is, I have table "temp" with 300 records
if i gave 25
i want 1-25 records from temp,
next time if i gave 75
i want 25-100 records from temp,
next time if i gave 200
i want records from 100-300
for next time if i gave 50
i want records from 1-50

推荐答案

CREATE PROCEDURE [dbo].[GetTempData]
(
@StartRow INT,
@NumberOfRows INT
)
AS BEGIN
SELECT * FROM
(
SELECT *, ROW_NUMBER() OVER(ORDER BY TempId) AS RowRank FROM Temp
) AS TempTable WHERE RowRank >= @StartRow AND RowRank < (@StartRow + @NumberOfRows)
END




请尝试此过程.希望您能找到解决方案,但必须传递两个参数,即开始行索引和记录数,这些参数必须从前端计算.
示例:-假设您要从表的第25行中获取100条记录,则必须分别发送两个参数25,100.




Try this procedure. Hope you will find your solution but you have to pass two parameters as start row index and number of records, that you have to calculate from front end.
Example :- Suppose you want 100 number of records from 25th row of table then you have to send two parameters as 25,100 respectively.


这篇关于如何获得最高记录和最高记录下方的下一次记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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