如何按指定的行数要求返回查询到的数据

yilinpang 2004-10-08 09:26:12
假设查询到1000条数据,我要求分10次返回,每次返回100个,
...全文
85 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yilinpang 2004-10-09
  • 打赏
  • 举报
回复
我的目的主要是想提高查询速度
General521 2004-10-08
  • 打赏
  • 举报
回复
参照这个:分页存储过程:

CREATE procedure fy
@rows int ,
@pages int
as
declare @stra varchar(300) --如果数据类型的长度不够,那么存储过程将不会执行.(造成空格的丢失,)
declare @strb varchar(300)
declare @strc varchar(300)
declare @strd varchar(300)
set @stra=' select top '+cast(@rows as varchar(10))+' * from people where [id] > '
set @strb=' (select max([id]) from (select top '+cast((@rows*(@pages-1)) as varchar(10))+' [id] from people order by [id] asc) a) '
set @strc=' order by [id] asc '
set @strd=' select top '+cast(@rows as varchar(10))+' * from people '
if @pages=1
begin
exec(@strd)
end
else
begin
exec(@stra+@strb+@strc)
end
GO

你可以做一个循环。
张海霖 2004-10-08
  • 打赏
  • 举报
回复
你具体要做什么?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧