一个不错的sql储存过程分页,储存过程 repeater,如果只是浏览数据的话,快就一个字... -尊龙游戏旗舰厅官网
尊龙游戏旗舰厅官网
收集整理的这篇文章主要介绍了
一个不错的sql储存过程分页,储存过程 repeater,如果只是浏览数据的话,快就一个字...
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
一个不错的sql储存过程分页,储存过程 repeater,如果只是浏览数据的话,快就一个字
create procedure selectpagedsql
(
@sql nvarchar(512),
@indexfield nvarchar(100),
@pagesize int=10,
@pageindex int=1,
@sort nvarchar(128)=@indexfield,
@totalcount int=0 output
)
as
declare @strsql nvarchar(1024)
set nocount on
set @strsql='
select @totalcount=count(*) from ('@sql') as t '
exec sp_executesql
@strsql,
n'@totalcount int=0 output',
@totalcount=@totalcount output
declare @itemcount int
set @itemcount=@totalcount-@pagesize*@pageindex
if(@itemcount<0)
set @itemcount=@itemcount@pagesize
else
set @itemcount=@pagesize
if(@itemcount<0)return 1
set @strsql='select * from
(select top 'str(@itemcount)' * from
(select top 'str(@pagesize*@pageindex)' * from
('@sql') as t0
order by '@indexfield' asc) as t1
order by '@indexfield' desc) as t2
order by ' @sort
exec sp_executesql
@strsql
go
----------------------------------
set quoted_identifier off
go
set ansi_nulls off
go
createprocedure commgetrecordbypage
@tblname varchar(255), -- 表名
@fldname varchar(255), -- 主键字段名
@pagesize int = 10, -- 页尺寸
@pageindex int = 1, -- 页码
@isrecount bit = 0, -- 返回记录总数, 非 0 值则返回
@ordertype bit = 0, -- 设置排序类型, 非 0 值则降序
@strwhere varchar(1000) = '' -- 查询条件 (注意: 不要加 where)
as
declare @strsql varchar(6000) -- 主语句
declare @strtmp varchar(100) -- 临时变量
declare @strorder varchar(400) -- 排序类型
if @ordertype != 0
begin
set @strtmp = '<(select min'
set @strorder = ' order by [' @fldname '] desc'
end
else
begin
set @strtmp = '>(select max'
set @strorder = ' order by [' @fldname '] asc'
end
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname '] where [' @fldname ']' @strtmp '(['
@fldname ']) from (select top ' str((@pageindex-1)*@pagesize) ' ['
@fldname '] from [' @tblname ']' @strorder ') as tbltmp)'
@strorder
if @strwhere != ''
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname '] where [' @fldname ']' @strtmp '(['
@fldname ']) from (select top ' str((@pageindex-1)*@pagesize) ' ['
@fldname '] from [' @tblname '] where ' @strwhere ' '
@strorder ') as tbltmp) and ' @strwhere ' ' @strorder
if @pageindex = 1
begin
set @strtmp =''
if @strwhere != ''
set @strtmp = ' where ' @strwhere
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname ']' @strtmp ' ' @strorder
end
if @isrecount != 0
set @strsql = 'select count(*) as total from [' @tblname ']' ' where ' @strwhere
exec (@strsql)
go
set quoted_identifier off
go
set ansi_nulls on
go
这个也不错啊
posted on 2007-08-05 09:40 江宇旋 阅读(...) 评论(...) 编辑 收藏
create procedure selectpagedsql
(
@sql nvarchar(512),
@indexfield nvarchar(100),
@pagesize int=10,
@pageindex int=1,
@sort nvarchar(128)=@indexfield,
@totalcount int=0 output
)
as
declare @strsql nvarchar(1024)
set nocount on
set @strsql='
select @totalcount=count(*) from ('@sql') as t '
exec sp_executesql
@strsql,
n'@totalcount int=0 output',
@totalcount=@totalcount output
declare @itemcount int
set @itemcount=@totalcount-@pagesize*@pageindex
if(@itemcount<0)
set @itemcount=@itemcount@pagesize
else
set @itemcount=@pagesize
if(@itemcount<0)return 1
set @strsql='select * from
(select top 'str(@itemcount)' * from
(select top 'str(@pagesize*@pageindex)' * from
('@sql') as t0
order by '@indexfield' asc) as t1
order by '@indexfield' desc) as t2
order by ' @sort
exec sp_executesql
@strsql
go
----------------------------------
set quoted_identifier off
go
set ansi_nulls off
go
createprocedure commgetrecordbypage
@tblname varchar(255), -- 表名
@fldname varchar(255), -- 主键字段名
@pagesize int = 10, -- 页尺寸
@pageindex int = 1, -- 页码
@isrecount bit = 0, -- 返回记录总数, 非 0 值则返回
@ordertype bit = 0, -- 设置排序类型, 非 0 值则降序
@strwhere varchar(1000) = '' -- 查询条件 (注意: 不要加 where)
as
declare @strsql varchar(6000) -- 主语句
declare @strtmp varchar(100) -- 临时变量
declare @strorder varchar(400) -- 排序类型
if @ordertype != 0
begin
set @strtmp = '<(select min'
set @strorder = ' order by [' @fldname '] desc'
end
else
begin
set @strtmp = '>(select max'
set @strorder = ' order by [' @fldname '] asc'
end
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname '] where [' @fldname ']' @strtmp '(['
@fldname ']) from (select top ' str((@pageindex-1)*@pagesize) ' ['
@fldname '] from [' @tblname ']' @strorder ') as tbltmp)'
@strorder
if @strwhere != ''
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname '] where [' @fldname ']' @strtmp '(['
@fldname ']) from (select top ' str((@pageindex-1)*@pagesize) ' ['
@fldname '] from [' @tblname '] where ' @strwhere ' '
@strorder ') as tbltmp) and ' @strwhere ' ' @strorder
if @pageindex = 1
begin
set @strtmp =''
if @strwhere != ''
set @strtmp = ' where ' @strwhere
set @strsql = 'select top ' str(@pagesize) ' * from ['
@tblname ']' @strtmp ' ' @strorder
end
if @isrecount != 0
set @strsql = 'select count(*) as total from [' @tblname ']' ' where ' @strwhere
exec (@strsql)
go
set quoted_identifier off
go
set ansi_nulls on
go
这个也不错啊
posted on 2007-08-05 09:40 江宇旋 阅读(...) 评论(...) 编辑 收藏
转载于:https://www.cnblogs.com/jiangyuxuan/archive/2007/08/05/843463.html
总结
以上是尊龙游戏旗舰厅官网为你收集整理的一个不错的sql储存过程分页,储存过程 repeater,如果只是浏览数据的话,快就一个字...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: