日期:2014-05-17  浏览次数:20853 次

谁能给个top not in 数据库存储过程分页的 sql啊
本帖最后由 rzxys 于 2014-01-07 14:04:25 编辑
谁能给个top not in 数据库存储过程分页的 sql啊,最好给注释

------解决方案--------------------
select * from (select rn=row_number() over (order by getdate()),* from tablename )
where rn between 第一頁 and  第一頁+每頁行數
------解决方案--------------------
现在一般都用row_number了。。。没多少人用top not in 了吧


select top 10 * from table
where id not in(select top 100 id from table)

------解决方案--------------------
这是sql语句啊
存储过程要建立在sql语句的基础上
如果要交作业的话 你应该把你的表的名称和结构发出来 以便我们直接给答案给你(我都习惯了
------解决方案--------------------
create proc 分页
@PageCount int,
@PageIndex int
as
begin
   select top 10 * from table
where id not in(select top 100 id from table)
end
------解决方案--------------------
create proc 分页
@PageCount int,
@PageIndex int
as
begin
   select top @PageCount * from table
where id not in(select top @PageCount*(@PageIndex-1) id from table)
end
------解决方案--------------------
 create  procedure SqlPager
@sqlstr nvarchar(4000), --查询字符串
@currentpage int, --第N页
@pagesize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
 @rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1, @rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 总页数--,@rowcount as 总行数,@currentpage as 当前页 
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize 
exec sp_cursorclose @P1
set nocount off
------解决方案--------------------
引用:
Quote: 引用:

现在一般都用row_number了。。。没多少人用top not in 了吧


select top 10 * from table
where id not in(select top 100 id from table)

我去网上查了 row_number 这个好像更好啊。谢谢


select * from (select rn=row_number() over (order&nbs