Sql server动态加载存储过程--分页
Posted 或三撇丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sql server动态加载存储过程--分页相关的知识,希望对你有一定的参考价值。
create procedure [dbo].[pro_getStu]
(
@pindex int, --最小是1,第1页
@psize int,
@name nvarchar,
@dbcount int out--总记录数
)
as
begin
(
@pindex int, --最小是1,第1页
@psize int,
@name nvarchar,
@dbcount int out--总记录数
)
as
begin
-----取符合条件的记录信息总数量
declare @Sqlcount NVARCHAR(MAX)
SET @Sqlcount = N‘SELECT @dbcount = COUNT(1) FROM DoFolder where 1=1 ‘
if @name is not null
begin
set @Sqlcount+=‘ and [DoFolderName] like ‘‘%‘[email protected]+‘%‘‘‘;
end
EXEC SP_EXECUTESQL @Sqlcount,N‘@dbcount int output‘,@dbcount output
-----取符合条件的记录信息
declare @sql varchar(2000);
set @sql=‘
select * from
(
select ROW_NUMBER() over(order by DoFolderName) as num,
[DoFolderID],[DoFolderName],[ParentID]
from DoFolder where 1=1 ‘;
if @name is not null
begin
set @sql+=‘and [DoFolderName] like ‘‘%‘[email protected]+‘%‘‘‘;
end
set @sql +=‘) temptable
--where num between ((页码-1)*几条+1) and (页码*几条)
where num between ‘+ convert( varchar,(@pindex-1)*@psize+1) +‘ and ‘+ convert(varchar,@pindex*@psize);
print(@sql);
exec(@sql);
end
以上是关于Sql server动态加载存储过程--分页的主要内容,如果未能解决你的问题,请参考以下文章