当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

动态的SQL分页

  alter procedure sp_aspnetpage

  @curpage int,

  @tablename varchar(50),--输入参数

  @count int output,--输出参数

  @order varchar(10),

  @key varchar(10),

  @pagesize int=2,

  @condition varchar(2000)='1=1'

  as

  begin

  set nocount on

  --设置开始行号

  declare @start_row_num int

  set @start_row_num=(@curpage-1)*@pagesize

  --设置动态sql语句

  declare @sql varchar(1000)

  set @sql='select top '+cast(@pagesize as varchar(20))+'* from '+@tablename+' where '+@condition+' and '+@key+' not in (select top '+convert(varchar(20),@start_row_num)+' '+@key+' from '+@tablename+ ' where '+@condition+' order by '+@order+') order by '+@order

  --获得总记录数

  declare @countnum nvarchar(4000)

  set @countnum='select @all=count(-1) from '+@tablename

  exec sp_executesql @countnum,N'@all int output',@count output

  --执行分页sql

  print @sql

  exec (@sql)

  end

相关内容
赞助商链接