请高人修改一下这个号称千万数量级的分页存储过程
存储过程内容如下:
CREATE PROCEDURE XEN_SP_Pagination
/*
参数说明:
1.Tables :表名称,视图
2.Topnum :总查询条数
2.Fields :查询字段,默认*
3.PrimaryKey :主关键字
4.Sort :排序语句,不带Order By 比如:NewsID Desc,OrderRows Asc
5.CurrentPage :当前页码
6.PageSize :分页尺寸
7.Filter :过滤语句,不带Where
8.Group :Group语句,不带Group By
***************************************************************/
(
@Tables varchar(1000),
@PrimaryKey varchar(100),
@Sort varchar(200) = NULL,
@CurrentPage int = 1,
@PageSize int = 10,
@Topnum varchar(10) = NULL,
@Fields varchar(1000) = '* ',
@Filter varchar(1000) = NULL,
@Group varchar(1000) = NULL
)
AS
/*默认排序*/
IF @Sort IS NULL OR @Sort = ' '
SET @Sort = @PrimaryKey
DECLARE @SortTable varchar(100)
DECLARE @SortName varchar(100)
DECLARE @strSortColumn varchar(200)
DECLARE @operator char(2)
DECLARE @type varchar(100)
DECLARE @prec int
/*设定排序语句.*/
IF CHARINDEX( 'DESC ',@Sort)> 0
BEGIN
SET @strSortColumn = REPLACE(@Sort, 'DESC ', ' ')
SET @operator = ' <= '
END
ELSE
BEGIN
IF CHARINDEX( 'ASC ', @Sort) = 0
SET @strSortColumn = REPLACE(@Sort, 'ASC ', ' ')
SET @operator = '> = '
END
IF CHARINDEX( '. ', @strSortColumn) > 0
BEGIN
SET @SortTable = SUBSTRING(@strSortColumn, 0, CHARINDEX( '. ',@strSortColumn))
SET @SortName = SUBSTRING(@strSortColumn, CHARINDEX( '. ',@strSortColumn) + 1, LEN(@strSortColumn))
END
ELSE
BEGIN
SET @SortTable = @Tables
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 = @SortTable AND c.name = @SortName
IF CHARINDEX( 'char ', @type) > 0
SET @type = @ty