熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

動態的SQL分頁

2022-06-13   來源: .NET編程 

  alter procedure sp_aspnetpage

  @curpage int

  @tablename varchar()輸入參數

  @count int output輸出參數

  @order varchar()

  @key varchar()

  @pagesize int=

  @condition varchar()==

  as

  begin

  set nocount on

  設置開始行號

  declare @start_row_num int

  set @start_row_num=(@curpage)*@pagesize

  設置動態sql語句

  declare @sql varchar()

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

  獲得總記錄數

  declare @countnum nvarchar()

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

  exec sp_executesql @countnumN@all int output@count output

  執行分頁sql

  print @sql

  exec (@sql)

  end


From:http://tw.wingwit.com/Article/program/net/201311/13386.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.