码迷,mamicode.com
首页 > 其他好文 > 详细

搜索+分页存储过程

时间:2016-08-02 00:56:24      阅读:207      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!