首页 > 其他 > 详细

搜索+分页存储过程

时间:2016-08-02 00:55:31      阅读:185      评论:0      收藏:0      [点我收藏+]
ALTER PROCEDURE Proc_MemorialHall_SeconSide
@Keyword nvarchar(100)=‘‘,
@BeginPage int ,
@PageCount int,
@RecordCount int output
AS
BEGIN
    SET NOCOUNT ON;
    declare @BeginIndex int=((@BeginPage-1)*@PageCount)+1
    declare @EndIndex int=(@BeginPage*@PageCount)
    declare @sql nvarchar(2000)
    declare @sqlCount nvarchar(2000)
    declare @condition nvarchar(100)=‘‘
    
    if(LEN(@Keyword)>0)
    begin
        set @condition=‘ and mh.Title like ‘‘%‘+@Keyword+‘%‘‘‘
    end
    
    set @sql=‘select * from(select mh.*,ROW_NUMBER() over(order by BuildDateTime desc) rowNumber from MemorialHall mh 
    inner join Member m on mh.MemberID=m.MemberID where mh.IsStop=0‘+@condition+‘) t 
    where rowNumber between ‘+CONVERT(varchar(100),@BeginIndex) +‘ and ‘+CONVERT(varchar(100),@EndIndex)
    
    set @sqlCount=‘select @RecordCount=count(*) from MemorialHall mh 
    inner join Member m on mh.MemberID=m.MemberID where mh.IsStop=0‘+@condition
    set @sql=@sqlCount+@sql
    print @sql
    exec sp_executesql @sql,N‘@RecordCount int output‘,@RecordCount output 
END

 

搜索+分页存储过程

原文:http://www.cnblogs.com/genesis/p/5727620.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!