存储过程 为 sql server 2000版本,请打开sql server 2000 的查询分析器执行下面的sql 语句。 程序用到的存储过程(仅支持主键排序)
ifexists (select*from dbo.sysobjects where id =object_id(n'[dbo].[sys_quicksortpaging]') andobjectproperty(id, n'isprocedure') =1) dropprocedure[dbo].[sys_quicksortpaging] go
/**//* 获取用于定位的字段*/ ifcharindex('desc',@orderby)>0 begin set@strsortcolumn=replace(@orderby, 'desc', '') set@operator='<=' end else begin ifcharindex('asc', @orderby) =0 set@strsortcolumn=replace(@orderby, 'asc', '') set@operator='>=' end
ifcharindex('.', @strsortcolumn) >0 begin set@sorttable=substring(@strsortcolumn, 0, charindex('.',@strsortcolumn)) set@sortname=substring(@strsortcolumn, charindex('.',@strsortcolumn) +1, len(@strsortcolumn)) end else begin set@sorttable=@table set@sortname=@strsortcolumn end
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 =@sorttableand c.name =@sortname
if@whereisnotnulland@where!='' begin set@strwhere=' where '+@where set@strwhereand=' and '+@where end else begin set@strwhere='' set@strwhereand='' end
if@groupbyisnotnulland@groupby!='' begin set@strgroupby=' group by '+@groupby end else begin set@strgroupby='' end
declare@strsqlnvarchar(4000) set@strsql=' select @recordcount = count (*) from '+@table+@strwhere+''+@strgroupby exec sp_executesql @strsql,n'@recordcount int output',@recordcount output--计算总页数 exec ( ' declare @sort '+@type+' set rowcount '+@strstartrow+' select @sort = '+@strsortcolumn+' from '+@table+@strwhere+''+@strgroupby+' order by '+@orderby+' set rowcount '+@strpagesize+' select '+@field+' from '+@table+' where '+@strsortcolumn+@operator+' @sort '+@strwhereand+''+@strgroupby+' order by '+@orderby ) go set quoted_identifier off go set ansi_nulls on go