sql语句分页和排序问题
一般的分页语句是selecttop"+pageSize+"*from表whereIdnotin(selecttop"+(pageNow-1)*pageSize+"Idfr...
一般的分页语句是 select top "+pageSize+" * from 表 where Id not in (select top "+(pageNow-1)*pageSize+" Id from 表)
如果带排序比如order by 某字段,的分页语句怎么写?谢谢 展开
如果带排序比如order by 某字段,的分页语句怎么写?谢谢 展开
2013-11-11
展开全部
create proc sp_page -- 数据库名,表名,字段名,第几页,每页行数
(@dataname varchar(20),@tablename varchar(20) ,@fieldname varchar(20),@page_cur int,@page_size int)
as
declare @sqlstr varchar(200)
set @sqlstr='select top '+cast( @page_size as varchar(20))+' * from '
+@dataname+'..'+@tablename+' where '+@fieldname+' not in ( select top '
+cast((@page_cur-1)*@page_size as varchar(20))+' '+@fieldname+' from '
+@dataname+'..'+@tablename+' order by '+@tablename+'.'@fieldname')'
execute(@sqlstr)
go
--exec sp_page pubs,jobs,job_id,3,2
(@dataname varchar(20),@tablename varchar(20) ,@fieldname varchar(20),@page_cur int,@page_size int)
as
declare @sqlstr varchar(200)
set @sqlstr='select top '+cast( @page_size as varchar(20))+' * from '
+@dataname+'..'+@tablename+' where '+@fieldname+' not in ( select top '
+cast((@page_cur-1)*@page_size as varchar(20))+' '+@fieldname+' from '
+@dataname+'..'+@tablename+' order by '+@tablename+'.'@fieldname')'
execute(@sqlstr)
go
--exec sp_page pubs,jobs,job_id,3,2
推荐于2018-04-24
展开全部
select aa.字段 from (select top "+pageSize+" * from 表 where Id not in (select top "+(pageNow-1)*pageSize+" Id from 表) aa order by aa.要排序的字段
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询