查询

awjx 2003-08-19 02:57:16
查询一张表,条件是:指定查询的起始行(@row),每页返回的行数(@page)。
即:从第@row行开始,每页返回@page行。请问该怎样写?
...全文
94 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2003-08-19
  • 打赏
  • 举报
回复
/*
用存储过程实现的分页程序
*/
CREATE procedure Department_pagination
@SelectStr nvarchar(1000),
@ColumnStr nvarchar (1000),
@OrderStr nvarchar (1000),
@CurrentPage int,
@PageCount int
as
declare @TimeName nvarchar(25)
declare @TableStr nvarchar(1000)

select @TimeName = convert(nvarchar(23), getdate(), 121)
set @TimeName = REPLACE(@TimeName, '.', '')
set @TimeName = REPLACE(@TimeName, ':', '')
set @TimeName = REPLACE(@TimeName, '-', '')
set @TimeName = REPLACE(@TimeName, ' ', '')

select @TableStr='create table ##Tab' + @TimeName + '(wb int identity,'
exec(@TableStr+@ColumnStr+')')
exec('insert into ##Tab' + @TimeName + ' ' + @SelectStr + ' order by ' + @OrderStr)
exec('select * from ##Tab' + @TimeName + ' where wb between ((' + @CurrentPage + '-1)*' + @PageCount + '+1) and ' + @CurrentPage + '*' + @PageCount + ' order by wb')
exec('drop table ##Tab' + @TimeName)
GO



参数1:select语句。2:字段列表。3:排序字段。4:当前页。5每页数目
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
查询N-M条记录。
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M-N * from #temptable where iid>=N

OR:

select top M-N * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段
txlicenhe 2003-08-19
  • 打赏
  • 举报
回复
Select identity(int,1,1) as id,* into #tmp from yourTable
select * from #tmp where id between @row and @row + @page
drop table #tmp
txlicenhe 2003-08-19
  • 打赏
  • 举报
回复
select identity(int,1,1) as id,* into #tmp from yourtable
select * from #tmp where id between @row and @row+@page
drop table #tmp
hjb111 2003-08-19
  • 打赏
  • 举报
回复
create proc p_record_row @row int,@page int
as
select identity(int,1,1) as idd,* into #t from yourtable
select * from #t where idd between @row and @row+@page

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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