mysql存储过程实现分页_存储过程实现分页

这篇文章介绍了如何在ASP.NET中使用存储过程AspNetPager进行分页查询,包括针对不同SQL版本的优化策略,如SQL Server 2000和2000以上版本的区别处理。重点在于创建存储过程和处理起始记录数、结束记录数、排序字段和分页大小等参数。
摘要由CSDN通过智能技术生成

USE [HDIS] GO /****** Object: StoredProcedure [dbo].[AspNetPager] Script Date: 12/30/2014 09:00:35 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create procedure [dbo].[AspNetPager] (@tablename nvarchar (1000), --表名 @filedname

USE [HDIS]

GO

/****** Object: StoredProcedure [dbo].[AspNetPager] Script Date: 12/30/2014 09:00:35 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

Create procedure [dbo].[AspNetPager]

(@tablename nvarchar (1000), --表名

@filedname nvarchar (4000), --查询的字段

@startIndex int, --起始记录数

@endIndex int, --结束记录数

@where nvarchar (4000), --条件 (不包含where)

@orderfiled nvarchar (100), --排序字段 (CreateDate desc)

@PageSize int,

@prmkeyName nvarchar (100),

@pageIndex int,

@docount bit)

as

begin

declare @date varchar(50),@sql nvarchar (4000) ,@i int

select @date =CONVERT(nvarchar(50), serverproperty('productversion'))

--if(CONVERT(int, SUBSTRING(@date,0,3))>8) ------sql2000以上

-- begin

-- if(@docount=1)

-- set @sql = 'select count(*) from ' + @tablename +' where ' + @where

-- else

-- begin

-- set @sql ='

-- with temptbl as (

-- SELECT ROW_NUMBER() OVER (ORDER BY '+ @orderfiled +' )AS Row, * from '+ @tablename +' where '+ @where +')

-- SELECT '+ @filedname +' FROM temptbl where Row between '+CONVERT(nvarchar(100),@startIndex) +' and '+CONVERT(nvarchar(100),@endIndex )

-- END

-- exec (@sql)

-- end

--else

begin -------sql2000

if(@docount=1)

set @sql = 'select count(*) from ' + @tablename +' where ' + @where

else

begin

set @i= CONVERT(nvarchar(100),@PageSize)*(CONVERT(nvarchar(100),@pageIndex)-1)

set @sql = 'SELECT TOP '+ CONVERT(nvarcha【本文来自鸿网互联 (http://www.68idc.cn)】r(100),@PageSize) +' *

FROM ' + @tablename +' WHERE ('+@where +' and

'+@prmkeyName+' NOT IN

(SELECT TOP '+CONVERT(nvarchar(100),@i)+' '

+@prmkeyName +'

FROM ' + @tablename +' WHERE ' + @where+' ORDER BY '+ @orderfiled +')) ORDER BY '+ @orderfiled

end

--print(@sql)

exec (@sql)

end

end

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值