一篇好用的通用分页存储进度,能够用在别的付出上啊,只要小小的更动就好了,有亟待的爱侣能够参照一下本款实例。
代码如下复制代码 /*通用分页存款和储蓄进度*/USE HotelManagementSystemGOIF
EXISTS(SELECT * FROM sys.objects WHERE
NAME=’cndoup_GetPageOfRecords’)DROP PROCEDURE
cndoup_GetPageOfRecordsGO–创制存款和储蓄进程CREATE PROCEDURE
cndoup_GetPageOfRecords@pageSize int = 20, –分页大小@currentPage int ,
–第几页@columns varchar(1000卡塔尔(قطر‎ = ‘*’, –要求获得的字段 @tableName
varchar(100卡塔尔, –需求查询的表 @condition varchar(1000卡塔尔 = ”, –查询条件,
不用加where关键字@ascColumn varchar(100State of Qatar = ”, –排序的字段名 (即 order
by column asc/desc卡塔尔国@bitOrderType bit = 0, –排序的门类
(0为升序,1为降序卡塔尔@pkColumn varchar(50卡塔尔(قطر‎ = ” –主键名称ASBEGIN
–存款和储蓄进程领头DECLARE @strTemp varchar(300卡塔尔DECLARE @strSql varchar(5000卡塔尔国–该存款和储蓄进度最终试行的语句DECLARE @strOrderType varchar(1000State of Qatar–排序类型语句 (order by column asc只怕order by column desc卡塔尔BEGINIF
@bitOrderType = 1 –降序BEGINSET @strOrderType = ‘ OQashqaiDEWrangler BY
‘+@ascColumn+’ DESC’SET @strTemp = ‘(SELECT min’ENDELSE–升序BEGINSET
@strOrderType = ‘ O揽胜DE福特Explorer BY ‘+@ascColumn+’ ASC’SET @strTemp = ‘(SELECT
max’ENDIF @currentPage = 1–第一页BEGINIF @condition != ”SET @strSql =
‘SELECT TOP ‘+STR(@pageSize)+’ ‘+@columns+’ FROM ‘+@tableName+’ WHERE
‘+@condition+@strOrderTypeELSESET @strSql = ‘SELECT TOP
‘+STR(@pageSize)+’ ‘+@columns+’ FROM ‘+@tableName+@strOrderTypeENDELSE–
其他页BEGINIF @condition !=”SET @strSql = ‘SELECT TOP
‘+STR(@pageSize)+’ ‘+@columns+’ FROM ‘+@tableName+’ WHERE ‘+@condition+’
AND ‘+@pkColumn+@strTemp+'(‘+@pkColumn+’)’+’ FROM (SELECT TOP
‘+STR((@currentPage-1)*@pageSize)+’ ‘+@pkColumn+’ FROM
‘+@tableName+’where’+@condition+@strOrderType+’) AS
TabTemp)’+@strOrderTypeELSESET @strSql = ‘SELECT TOP ‘+STR(@pageSize)+’
‘+@columns+’ FROM ‘+@tableName+’ WHERE
‘+@pkColumn+@strTemp+'(‘+@pkColumn+’)’+’ FROM (SELECT TOP
‘+STR((@currentPage-1)*@pageSizeState of Qatar+’ ‘+@pkColumn+’ FROM
‘+@tableName+@strOrderType+’State of Qatar AS TabTempState of Qatar’+@strOrderTypeENDENDEXEC
(@strSql卡塔尔(قطر‎END–存款和储蓄进程停止–分页得到客房音信列表测验EXEC
cndoup_GetPageOfRecords 20,2,’房间号=RoomNum,房间状态=(SELECT
RoomTypeDes FROM RoomType WHERE
RoomTypeID=Room.RoomTypeID卡塔尔国,房间状态=(SELECT LANDSDec FROM RoomStatus WHERE
RoomStatusID=Room.RoomStatusID卡塔尔国,床位数=BedNum,楼层=Floors,描述=RoomDes,备注=RoomRemark’,’Room’,”,’RoomID’,0,’RoomID’–依照房间号获得客房音讯测量试验EXEC
cndoup_GetPageOfRecords 1,1,’房间号=RoomNum,房间状态=(SELECT
RoomTypeDes FROM RoomType WHERE
RoomTypeID=Room.RoomTypeID卡塔尔(قطر‎,房间状态=(SELECT MuranoSDec FROM RoomStatus WHERE
RoomStatusID=Room.RoomStatusIDState of Qatar,BedNum,Floors,RoomDes,RoomRemark’,’Room’,’RoomNum=304′,’RoomID’,0,’RoomID’

/*通用分页存款和储蓄进程*/
USE HotelManagementSystem
GO
IF EXISTS(SELECT * FROM sys.objects WHERE
NAME=’cndoup_GetPageOfRecords’)
DROP PROCEDURE cndoup_GetPageOfRecords
GO
–创立存款和储蓄进度
CREATE PROCEDURE cndoup_GetPageOfRecords
@pageSize int = 20,                        –分页大小
@currentPage int ,                        –第几页
@columns varchar(1000) = ‘*’,              –供给获得的字段
@tableName varchar(100卡塔尔国,                  –须要查询的表 
@condition varchar(1000卡塔尔(قطر‎ = ”,            –查询条件,
不用加where关键字
@ascColumn varchar(100卡塔尔(قطر‎ = ”,              –排序的字段名 (即 order by
column asc/desc卡塔尔(قطر‎
@bitOrderType bit = 0,                    –排序的花色
(0为升序,1为降序卡塔尔
@pkColumn varchar(50卡塔尔 = ”                –主键名称

复制代码 代码如下:–使用验证
本代码适用于MsSql2003,对于其他数据库也可用.但没必要 –成立存款和储蓄过程CREATE PROCEDURE pagination @tblName varchar(255卡塔尔, — 表名 @strGetFields
varchar(1000卡塔尔 = ‘*’, — 要求回到的列 @fldName varchar(255卡塔尔(قطر‎=”, —
排序的字段名(可含蓄如TABLE.FLDNAME情势) @PageSize int = 10, — 页尺寸
@PageIndex int = 1, — 页码 @doCount bit = 0, — 重返记录总量, 非 0
值则赶回 @OrderType bit = 0, — 设置排序类型, 非 0 值则降序 @strWhere
varchar(1500) = ” — 查询条件 (注意: 不要加 where卡塔尔 AS declare @strSQL
varchar(5000卡塔尔(قطر‎ — 主语句 declare @strTmp varchar(110State of Qatar — 临时变量 declare
@strOrder varchar(400卡塔尔(قطر‎ — 排序类型 declare @fldName_t varchar(255卡塔尔国 —
在分页时用的排序字段名,不带有多表并列时的表名 set @fldName_t =
right(@fldName,len(@fldName)-CHARINDEX(‘.’,@fldName)) if @doCount != 0
begin if @strWhere !=” set @strSQL = ‘select count(*) as Total from ‘

小说也是从朋友这里抄来的五个不利的sql分页存款和储蓄进度实现,听大人讲作用相比高的二个储存进程,有亟待的同窗能够领悟一下或提供越来越好的建设方案。

AS
BEGIN                                          –存款和储蓄进度开首
DECLARE @strTemp varchar(300)
DECLARE @strSql varchar(5000卡塔尔(قطر‎              –该存款和储蓄进度最终实行的话语
DECLARE @strOrderType varchar(1000卡塔尔国        –排序类型语句 (order by
column asc或许order by column descState of Qatar

  • @tblName + ‘ where ‘+@strWhere else set @strSQL = ‘select count(*卡塔尔(قطر‎ as
    Total from ‘ + @tblName + ” end
    –以上代码的意思是只要@doCount传递过来的不是0,就实行总额计算。以下的具备代码都以@doCount为0的情状else begin if @OrderType != 0 begin set @strTmp = ‘(select min’ set
    @strOrder = ‘ order by ‘ + @fldName +’ desc’
    –借使@OrderType不是0,就试行降序,那句很要紧! end else begin set
    @strTmp = ‘(select max’ set @strOrder = ‘ order by ‘ + @fldName +’ asc’
    end if @PageIndex = 1 begin if @strWhere != ” set @strSQL = ‘select top
    ‘ + str(@PageSize卡塔尔 +’ ‘+@strGetFields+ ‘ from ‘ + @tblName + ‘ where ‘ +
    @strWhere + ‘ ‘ + @strOrder else set @strSQL = ‘select top ‘ +
    str(@PageSizeState of Qatar +’ ‘+@strGetFields+ ‘ from ‘+ @tblName + ‘ ‘+ @strOrder
    –要是是率先页就举办以上代码,那样会加快施行进程 end else begin
    –以下代码授予了@strSQL以真正实行的SQL代码 set @strSQL = ‘select top ‘ +
    str(@PageSize卡塔尔(قطر‎ +’ ‘+@strGetFields+ ‘ from ‘+ @tblName + ‘ where ‘ +
    @fldName + ‘ ‘ + @strTmp + ‘ (‘+ @fldName_t + ‘) from (select top ‘ +
    str((@PageIndex-1)*@PageSize) + ‘ ‘+ @fldName + ‘ from ‘ + @tblName +
    ” + @strOrder + ‘) as tblTmp)’+ @strOrder if @strWhere != ” set
    @strSQL = ‘select top ‘ + str(@PageSize) +’ ‘+@strGetFields+ ‘ from ‘+
    @tblName + ‘ where ‘ + @fldName + ‘ ‘ + @strTmp + ‘ (‘+ @fldName_t + ‘)
    from (select top ‘ + str((@PageIndex-1)*@PageSize) + ‘ ‘+ @fldName + ‘
    from ‘ + @tblName + ‘ where ‘ + @strWhere + ‘ ‘+ @strOrder + ‘) as
    tblTmp) and ‘ + @strWhere + ‘ ‘ + @strOrder end end exec (@strSQL) go
    –测试 create table news –建表 ( n_id int iDENTITY(1,1) primary key,
    n_title char(200), n_content text State of Qatar –写循环插入1000000条的数码 create
    proc tt as declare @i int set @i=0 while(@i1000000State of Qatar begin insert into
    news(n_title,n_content) values(‘sb’,’dsfsdfsd’) set @i=@i+1 end exec
    tt exec pagination ‘news’,’*’,’n_id’,1000,2,0,0,” 第二篇复制代码 代码如下:自个儿改写的三个分页存款和储蓄进程CREATE PROC Paging ( @pageSize int, @pageIndex int, @pageFieldnvarchar(32State of Qatar, @countTotal bit=1, @田野先生Query nvarchar(512State of Qatar, @tableQuery
    nvarchar(512卡塔尔(قطر‎, @whereQuery nvarchar(2048卡塔尔(قطر‎, @orderQuery nvarchar(512State of Qatar 卡塔尔(قطر‎AS DECLARE @bdate Datetime SET @bdate = getdate(卡塔尔国 DECLARE @itemcount int
    SET @itemcount=@pageIndex*@pageSize DECLARE @itemlowwer int SET
    @itemlowwer=(@pageIndex-1)*@pageSize DECLARE @cmd nvarchar(3062) IF
    @pageIndex=1 SET @cmd =’SELECT TOP ‘+CAST(@pageSize AS NVARCHAR)+’
    ‘+@fieldQuery+’ FROM ‘+@tableQuery+’ WHERE ‘+@whereQuery+’ ORDER BY
    ‘+@orderQuery ELSE SET @cmd=’SELECT ‘+@fieldQuery+’ FROM ‘+@tableQuery+’
    WHERE ‘+@pageField+’ IN (SELECT TOP ‘+CAST(@itemcount as nvarchar)+’
    ‘+@pageField+’ FROM ‘+@tableQuery+’ WHERE ‘+@whereQuery+’ ORDER BY ‘+
    @orderQuery+’) AND ‘+@pageField+’ NOT IN (SELECT TOP ‘ +CAST(@itemlowwer
    as nvarchar)+’ ‘+@pageField+’ FROM ‘+@tableQuery+’ WHERE ‘+@whereQuery+’
    ORDER BY ‘+ @orderQuery+’)’ –print @cmd EXEC(@cmd) SELECT DATEDIFF( ms ,
    @bdate , getdate() ) IF @countTotal =1 BEGIN SET @cmd = ‘SELECT COUNT(
    0) FROM ‘+@tableQuery+’ WHERE ‘+@whereQuery EXEC(@cmd) END GO

以此还以为不错的八个存款和储蓄进程

BEGIN
IF @bitOrderType = 1     –降序
BEGIN
SET @strOrderType = ‘ ORDER BY '+@ascColumn+' DESC’
SET @strTemp = ‘ <(SELECT min’
END
ELSE –升序
BEGIN
SET @strOrderType = ‘ ORDER BY '+@ascColumn+' ASC’
SET @strTemp = ‘>(SELECT max’
END

代码如下复制代码

IF @currentPage = 1 –第一页
BEGIN
IF @condition != ”
SET @strSql = ‘SELECT TOP ‘+STR(@pageSize)+’ '+@columns+' FROM
'+@tableName+
‘ WHERE '+@condition+@strOrderType
ELSE
SET @strSql = ‘SELECT TOP ‘+STR(@pageSize)+’ '+@columns+' FROM
'+@tableName+@strOrderType
END

/****** 对象: StoredProcedure [dbo].[P_viewPage] 脚本日期:
05/14/二零一二 08:49:34 ******/SET ANSI_NULLS ONGOSET
QUOTED_IDENTIFIER ONGO

ELSE — 其他页
BEGIN
IF @condition !=”
SET @strSql = ‘SELECT TOP ‘+STR(@pageSize)+’ '+@columns+' FROM
'+@tableName+
‘ WHERE '+@condition+' AND '+@pkColumn+@strTemp+'('+@pkColumn+')'+'
FROM (SELECT TOP ‘+STR((@currentPage-1)*@pageSize)+
'+@pkColumn+' FROM '+@tableName+@strOrderType+') AS
TabTemp)’+@strOrderType
ELSE
SET @strSql = ‘SELECT TOP ‘+STR(@pageSize)+’ '+@columns+' FROM
'+@tableName+
‘ WHERE '+@pkColumn+@strTemp+'('+@pkColumn+')'+' FROM (SELECT TOP
‘+STR((@currentPage-1)*@pageSize)+’ '+@pkColumn+
‘ FROM '+@tableName+@strOrderType+') AS TabTemp)’+@strOrderType
END

create PROC [dbo].[P_viewPage]– Add the parameters for the stored
procedure here@TableName VARCHAEnclave(200卡塔尔(قطر‎, –表名@FieldList VARCHA冠道(贰零零壹卡塔尔(قطر‎,
–呈现列名,如若是任何字段则为*@PrimaryKey VARCHAEvoque(100卡塔尔(قطر‎,
–单一主键或独一值键@Where VARCHA英菲尼迪Q60(8000卡塔尔,
–查询条件不含’where’字符,如id10 and len(userid卡塔尔9@Order VARCHA福特Explorer(1000卡塔尔国,
–排序不含’order by’字符,如id asc,userid
desc,必得钦命asc或desc–注意当@SortType=3时生效,记住一定要在终极加上主键,不然会令你相比较烦懑@SortType
INT, –排序法则1:正序asc 2:倒序desc 3:多列排序方法@RecorderCount INT,
–记录总的数量0:会回去总记录@PageSize INT, –每页输出的记录数@PageIndex INT,
–当前页数@TotalCount INT OUTPUT, –记再次回到总记录@TotalPageCount INT
OUTPUT –重返总页数AS– SET NOCOUNT ON added to prevent extra result
sets from– interfering with SELECT statements.SET NOCOUNT ONIF
ISNULL(@TotalCount,”卡塔尔 = ” SET @TotalCount = 0SET @Order =
RTPAJEROIM(LTEscortIM(@OrderState of QatarState of QatarSET @PrimaryKey = RT奥德赛IM(LTPRADOIM(@PrimaryKey卡塔尔(قطر‎卡塔尔国SET
@FieldList = REPLACE(RTOdysseyIM(LTXC60IM(@FieldListState of QatarState of Qatar,’ ‘,”State of QatarWHILE CHA讴歌ZDXINDEX(‘,
‘,@Order卡塔尔国 0 OOdyssey CHA牧马人INDEX(‘ ,’,@Order卡塔尔国 0BEGINSET @Order =
REPLACE(@Order,’, ‘,’,’卡塔尔(قطر‎SET @Order = REPLACE(@Order,’ ,’,’,’State of QatarENDIF
ISNULL(@TableName,”State of Qatar = ” O纳瓦拉 ISNULL(@FieldList,”State of Qatar = ”O昂CoraISNULL(@PrimaryKey,”State of Qatar = ”OOdyssey @SortType 1 OCR-V @SortType 3O福睿斯@RecorderCount 0 O瑞虎 @PageSize 0 OENVISION @PageIndex 0BEGIN
PGL450INT(‘EPAJERO福睿斯_00参数错误’卡塔尔 RETU索罗德NENDIF @SortType = 3BEGINIF
(UPPE汉兰达(HavalIGHT(@Order,4卡塔尔卡塔尔!=’ ASC’ AND UPPER(RIGHT(@Order,5))!=’
DESC’)BEGIN PRINT(‘ERR_02排序错误’卡塔尔(قطر‎ RETULX570N ENDENDDECLARE @new_where1
VARCHAR(8000)DECLARE @new_where2 VARCHAR(8000)DECLARE @new_order1
VARCHAR(1000)DECLARE @new_order2 VARCHAR(1000)DECLARE @new_order3
VARCHAR(1000)DECLARE @Sql VARCHAR(8000)DECLARE @SqlCount
NVARCHAR(4000)IF ISNULL(@where,”) = ”BEGINSET @new_where1 = ‘ ‘SET
@new_where2 = ‘ WHERE ‘ENDELSEBEGINSET @new_where1 = ‘ WHERE ‘ +
@whereSET @new_where2 = ‘ WHERE ‘ + @where + ‘ AND ‘ENDIF
ISNULL(@order,”) = ” OR @SortType = 1 OR @SortType = 2BEGINIF
@SortType = 1 BEGIN SET @new_order1 = ‘ ORDER BY ‘ + @PrimaryKey + ‘
ASC’ SET @new_order2 = ‘ ORDER BY ‘ + @PrimaryKey + ‘ DESC’ ENDIF
@SortType = 2 BEGIN SET @new_order1 = ‘ ORDER BY ‘ + @PrimaryKey + ‘
DESC’ SET @new_order2 = ‘ ORDER BY ‘ + @PrimaryKey + ‘ ASC’
ENDENDELSEBEGINSET @new_order1 = ‘ ORDER BY ‘ + @OrderENDIF @SortType =
3 AND CHARINDEX(‘,’+@PrimaryKey+’ ‘,’,’+@Order)0BEGINSET @new_order1 =
‘ ORDER BY ‘ + @OrderSET @new_order2 = @Order + ‘,’SET @new_order2 =
REPLACE(REPLACE(@new_order2,’ASC,’,'{ASC},’),’DESC,’,'{DESC},’)SET
@new_order2 =
REPLACE(REPLACE(@new_order2,'{ASC},’,’DESC,’),'{DESC},’,’ASC,’)SET
@new_order2 = ‘ ORDER BY ‘ +
SUBSTRING(@new_order2,1,LEN(@new_order2)-1)IF @FieldList ‘*’ BEGIN
SET @new_order3 = REPLACE(REPLACE(@Order + ‘,’,’ASC,’,’,’),’DESC,’,’,’)
SET @FieldList = ‘,’ + @FieldList WHILE CHARINDEX(‘,’,@new_order3)0
BEGIN IF
CHARINDEX(SUBSTRING(‘,’+@new_order3,1,CHARINDEX(‘,’,@new_order3)),’,’+@FieldList+’,’)0
BEGIN SET @FieldList = @FieldList + ‘,’ +
SUBSTRING(@new_order3,1,CHARINDEX(‘,’,@new_order3)) END SET
@new_order3 =
SUBSTRING(@new_order3,CHARINDEX(‘,’,@new_order3)+1,LEN(@new_order3))
END SET @FieldList = SUBSTRING(@FieldList,2,LEN(@FieldList)) ENDENDSET
@SqlCount = ‘SELECT
@TotalCount=COUNT(*),@TotalPageCount=CEILING((COUNT(*)+0.0)/’+
CAST(@PageSize AS VARCHAR)+’) FROM ‘ + @TableName + @new_where1IF
@RecorderCount = 0BEGINEXEC SP_EXECUTESQL @SqlCount,N’@TotalCount INT
OUTPUT,@TotalPageCount INT OUTPUT’,@TotalCount OUTPUT,@TotalPageCount
OUTPUTENDELSEBEGINSELECT @TotalCount = @RecorderCountENDIF @PageIndex
CEILING((@TotalCount+0.0卡塔尔国/@PageSize卡塔尔BEGINSET @PageIndex =
CEILING((@TotalCount+0.0卡塔尔(قطر‎/@PageSizeState of QatarENDIF @PageIndex = 1 OLacrosse @PageIndex =
CEILING((@TotalCount+0.0卡塔尔国/@PageSizeState of QatarBEGINIF @PageIndex = 1
–重返第一页数据 BEGIN SET @Sql = ‘SELECT TOP ‘ + STRAV4(@PageSize卡塔尔国 + ‘ ‘ +
@FieldList + ‘ FROM ‘ + @TableName + @new_where1 + @new_order1 ENDIF
@PageIndex = CEILING((@TotalCount+0.0卡塔尔(قطر‎/@PageSize卡塔尔国 –再次回到最后一页数据
BEGIN SET @Sql = ‘SELECT TOP ‘ + ST本田UR-V(@PageSize卡塔尔国 + ‘ ‘ + @FieldList + ‘
FROM (‘ + ‘SELECT TOP ‘ +
STWrangler(ABS(@PageSize*@PageIndex-@TotalCount-@PageSize)) + ‘ ‘ + @FieldList

END
EXEC (@strSql)
END

  • ‘ FROM ‘ + @TableName + @new_where1 + @new_order2 + ‘ ) AS TMP ‘ +
    @new_order1 ENDENDELSEBEGINIF @SortType = 1 –仅主键正序排序 BEGIN IF
    @PageIndex = CEILING((@TotalCount+0.0卡塔尔国/@PageSize卡塔尔/2 –正向检索 BEGIN SET
    @Sql = ‘SELECT TOP ‘ + STEvoque(@PageSize卡塔尔 + ‘ ‘ + @FieldList + ‘ FROM ‘ +
    @TableName + @new_where2 + @PrimaryKey + ‘ ‘ + ‘(SELECT MAX(‘ +
    @PrimaryKey + ‘) FROM (SELECT TOP ‘ + STR(@PageSize*(@PageIndex-1)) + ‘
    ‘ + @PrimaryKey + ‘ FROM ‘ + @TableName + @new_where1 + @new_order1 +’
    ) AS TMP) ‘+ @new_order1 END ELSE –反向寻觅 BEGIN SET @Sql = ‘SELECT
    TOP ‘ + ST安德拉(@PageSize卡塔尔(قطر‎ + ‘ ‘ + @FieldList + ‘ FROM (‘ + ‘SELECT TOP ‘ +
    ST福特Explorer(@PageSize卡塔尔国 + ‘ ‘ + @FieldList + ‘ FROM ‘ + @TableName + @new_where2
  • @PrimaryKey + ‘ ‘ + ‘(SELECT MIN(‘ + @PrimaryKey + ‘) FROM (SELECT TOP
    ‘ + STR(@TotalCount-@PageSize*@PageIndex) + ‘ ‘ + @PrimaryKey + ‘ FROM
    ‘ + @TableName + @new_where1 + @new_order2 +’ ) AS TMP) ‘+
    @new_order2 + ‘ ) AS TMP ‘ + @new_order1 END ENDIF @SortType = 2
    –仅主键反序排序 BEGIN IF @PageIndex =
    CEILING((@TotalCount+0.0卡塔尔国/@PageSize卡塔尔国/2 –正向检索 BEGIN SET @Sql =
    ‘SELECT TOP ‘ + STPAJERO(@PageSize卡塔尔 + ‘ ‘ + @FieldList + ‘ FROM ‘ +
    @TableName + @new_where2 + @PrimaryKey + ‘ ‘ + ‘(SELECT MIN(‘ +
    @PrimaryKey + ‘) FROM (SELECT TOP ‘ + STR(@PageSize*(@PageIndex-1)) + ‘
    ‘ + @PrimaryKey +’ FROM ‘+ @TableName + @new_where1 + @new_order1 + ‘)
    AS TMP) ‘+ @new_order1 END ELSE –反向寻找 BEGIN SET @Sql = ‘SELECT TOP
    ‘ + ST大切诺基(@PageSize卡塔尔国 + ‘ ‘ + @FieldList + ‘ FROM (‘ + ‘SELECT TOP ‘ +
    STTiguan(@PageSize卡塔尔 + ‘ ‘ + @FieldList + ‘ FROM ‘ + @TableName + @new_where2
  • @PrimaryKey + ‘ ‘ + ‘(SELECT MAX(‘ + @PrimaryKey + ‘) FROM (SELECT TOP
    ‘ + STR(@TotalCount-@PageSize*@PageIndex) + ‘ ‘ + @PrimaryKey + ‘ FROM
    ‘ + @TableName + @new_where1 + @new_order2 +’ ) AS TMP) ‘+
    @new_order2 + ‘ ) AS TMP ‘ + @new_order1 END ENDIF @SortType = 3
    –多列排序,必须含有主键,且放置最终,不然不管理 BEGIN IF CHA福睿斯INDEX(‘,’
  • @PrimaryKey + ‘ ‘,’,’ + @Order) = 0 BEGIN PRINT(‘ERR_02’State of Qatar RETU科雷傲N END
    IF @PageIndex = CEILING((@TotalCount+0.0卡塔尔(قطر‎/@PageSize卡塔尔/2 –正向检索 BEGIN
    SET @Sql = ‘SELECT TOP ‘ + STCRUISER(@PageSize卡塔尔 + ‘ ‘ + @FieldList + ‘ FROM (
    ‘ + ‘SELECT TOP ‘ + ST猎豹CS6(@PageSize卡塔尔国 + ‘ ‘ + @菲尔德List + ‘ FROM ( ‘ + ‘
    SELECT TOP ‘ + ST揽胜(@PageSize*@PageIndex) + ‘ ‘ + @FieldList + ‘ FROM ‘
  • @TableName + @new_where1 + @new_order1 + ‘ ) AS TMP ‘ + @new_order2
  • ‘ ) AS TMP ‘ + @new_order1 END ELSE –反向寻觅 BEGIN SET @Sql =
    ‘SELECT TOP ‘ + ST冠道(@PageSize卡塔尔国 + ‘ ‘ + @菲尔德List + ‘ FROM ( ‘ + ‘SELECT
    TOP ‘ + ST讴歌ZDX(@PageSize卡塔尔 + ‘ ‘ + @FieldList + ‘ FROM ( ‘ + ‘ SELECT TOP ‘
  • STR(@TotalCount-@PageSize *@PageIndex+@PageSize) + ‘ ‘ + @FieldList +
    ‘ FROM ‘ + @TableName + @new_where1 + @new_order2 + ‘ ) AS TMP ‘ +
    @new_order1 + ‘ ) AS TMP ‘ + @new_order1 END ENDENDEXEC(@Sql)

–存款和储蓄进程甘休

–输出内容SELECT @TotalCount as N’@TotalCount’, @TotalPageCount as
N’@TotalPageCount’

/*测试*/
–分页获得客房音讯列表测量试验
EXEC cndoup_GetPageOfRecords 20,2,’房间号=RoomNum,
房间状态=(SELECT RoomTypeDes FROM RoomType WHERE
RoomTypeID=Room.RoomTypeID卡塔尔国,
房间状态=(SELECT TiggoSDec FROM RoomStatus WHERE
RoomStatusID=Room.RoomStatusID卡塔尔国,
床位数=BedNum,
楼层=Floors,
描述=RoomDes,
备注=RoomRemark’,’Room’,”,’RoomID’,0,’RoomID’

再享受一个,三个比较立异的囤积进度:(注:此存款和储蓄进程使用了sql二〇〇七函数,适用于sql二〇〇四5Infiniti以上版本卡塔尔国

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注