关于分页加模糊查询的存储过程
Posted huosanpie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于分页加模糊查询的存储过程相关的知识,希望对你有一定的参考价值。
select [Uid],[Usname],[Uname],[Urole],[Upicture] from Us
create proc Upage
(
@pageindex int, ---当前页
@pagesize int, ---显示几条
@pagecount int out, ---总条数
@name varchar(50) ---查询名称参数
)
as
---判断有没有查询的参数
if(@name is null)
begin
---查询总记录数
select @pagecount=COUNT(*) from Us;
select * from(select ROW_NUMBER() over(order by Usname)as num, [Uid],[Usname],[Uname],[Urole],[Upicture] from Us ) temptable where num between ((@pageindex-1)*@pagesize+1) and (@pageindex*@pagesize)
end
else
begin
---查询总记录数
select @pagecount=COUNT(*) from Us where Usname like ‘%‘[email protected]+‘%‘;
select * from(select ROW_NUMBER() over(order by Usname)as num, [Uid],[Usname],[Uname],[Urole],[Upicture] from Us where Usname like ‘%‘[email protected]+‘%‘) temptable where num between ((@pageindex-1)*@pagesize+1) and (@pageindex*@pagesize)
---where num between((页码-1)*几条+1) and (页码*几条)
end
(
@pageindex int, ---当前页
@pagesize int, ---显示几条
@pagecount int out, ---总条数
@name varchar(50) ---查询名称参数
)
as
---判断有没有查询的参数
if(@name is null)
begin
---查询总记录数
select @pagecount=COUNT(*) from Us;
select * from(select ROW_NUMBER() over(order by Usname)as num, [Uid],[Usname],[Uname],[Urole],[Upicture] from Us ) temptable where num between ((@pageindex-1)*@pagesize+1) and (@pageindex*@pagesize)
end
else
begin
---查询总记录数
select @pagecount=COUNT(*) from Us where Usname like ‘%‘[email protected]+‘%‘;
select * from(select ROW_NUMBER() over(order by Usname)as num, [Uid],[Usname],[Uname],[Urole],[Upicture] from Us where Usname like ‘%‘[email protected]+‘%‘) temptable where num between ((@pageindex-1)*@pagesize+1) and (@pageindex*@pagesize)
---where num between((页码-1)*几条+1) and (页码*几条)
end
以上是关于关于分页加模糊查询的存储过程的主要内容,如果未能解决你的问题,请参考以下文章