create procedure usp_paginglarge
@tablenames varchar(200), --表名,可以是多個表,但不能用別名
@primarykey varchar(100), --主鍵,可以為空,但@order為空時該值不能為空
@fields varchar(200), --要取出的字段,可以是多個表的字段,可以為空,為空表示select *
@pagesize int, --每頁記錄數
@currentpage int, --當前頁,0表示第1頁
@filter varchar(200) = '', --條件,可以為空,不用填 where
@group varchar(200) = '', --分組依據,可以為空,不用填 group by
@order varchar(200) = '' --排序,可以為空,為空缺省按主鍵公升序排列,不用填 order by
asbegin
declare @sortcolumn varchar(200)
declare @operator char(2)
declare @sorttable varchar(200)
declare @sortname varchar(200)
if @fields = ''
set @fields = '*'
if @filter = ''
set @filter = 'where 1=1'
else
set @filter = 'where ' + @filter
if @group <>''
set @group = 'group by ' + @group
if @order <> ''
begin
declare @pos1 int, @pos2 int
set @order = replace(replace(@order, ' asc', ' asc'), ' desc', ' desc')
if charindex(' desc', @order) > 0
if charindex(' asc', @order) > 0
begin
if charindex(' desc', @order) < charindex(' asc', @order)
set @operator = '<='
else
set @operator = '>='
endelse
set @operator = '<='
else
set @operator = '>='
set @sortcolumn = replace(replace(replace(@order, ' asc', ''), ' desc', ''), ' ', '')
set @pos1 = charindex(',', @sortcolumn)
if @pos1 > 0
set @sortcolumn = substring(@sortcolumn, 1, @pos1-1)
set @pos2 = charindex('.', @sortcolumn)
if @pos2 > 0
begin
set @sorttable = substring(@sortcolumn, 1, @pos2-1)
if @pos1 > 0
set @sortname = substring(@sortcolumn, @pos2+1, @pos1-@pos2-1)
else
set @sortname = substring(@sortcolumn, @pos2+1, len(@sortcolumn)-@pos2)
endelse
begin
set @sorttable = @tablenames
set @sortname = @sortcolumn
endend
else
begin
set @sortcolumn = @primarykey
set @sorttable = @tablenames
set @sortname = @sortcolumn
set @order = @sortcolumn
set @operator = '>='
enddeclare @type varchar(50)
declare @prec int
select @type=t.name, @prec=c.prec
from sysobjects o
join syscolumns c on o.id=c.id
join systypes t on c.xusertype=t.xusertype
where o.name = @sorttable and c.name = @sortname
if charindex('char', @type) > 0
set @type = @type + '(' + cast(@prec as varchar) + ')'
declare @toprows int
set @toprows = @pagesize * @currentpage + 1
print @toprows
print @operator
exec('
declare @sortcolumnbegin ' + @type + '
set rowcount ' + @toprows + '
select @sortcolumnbegin=' + @sortcolumn + ' from ' + @tablenames + ' ' + @filter + ' ' + @group + ' order by ' + @order + '
set rowcount ' + @pagesize + '
select ' + @fields + ' from ' + @tablenames + ' ' + @filter + ' and ' + @sortcolumn + '' + @operator + '@sortcolumnbegin ' + @group + ' order by ' + @order + '
endgo
這個技持多字段排序但不支援 text型別的輸出
set cn=server.createobject("adodb.connection")
cn.open "driver=;uid=sa;pwd=abc;database=yangzhi886a;server=zhao"
set rs =server.createobject("adodb.recordset")
rs.open "exec usp_paginglarge 'wz_list','','id,content','10',1,'','','id desc,date asc'",cn,1,1
while not rs.eof
response.write rs("content")&"
"rs.movenext
wend
content的值 一值 為空不知道為什麼
目前用id,convert(varchar(10),content) 來解決
分頁儲存過程 分頁儲存過程
分頁儲存過程 alter proc dbo p pageshow pagesize int,每頁大小 currentpage int out,當前頁 housename nvarchar 50 房產名稱 totalcount int out,總記錄數 totalpage int out 總頁數 as...
乙個分頁儲存過程
page language c import namespace system.data import namespace system.data.sqlclient 訂單號 服務專案 預訂日期 操作人員 分配狀態 databinder.eval container.dataitem,offerid...
兩個分頁儲存過程
drop proc dbo up getrecordbypage gocreate procedure dbo up getrecordbypage tblname varchar 255 表名 fldname varchar 255 主鍵欄位名 strcontent nvarchar 255 查詢...