SQL Stored Procedure Paging

Source: Internet
Author: User

CREATE PROC p_team_gettemalist @pageindex int, @pagesize int, @keywords VARCHAR (200),--fuzzy query name tag @cityco        De VARCHAR, @verifyStatus int =0,---1 All 0 did not pass the 1 audit through @orderby int, @TotalCount int Outputas BEGIN  DECLARE @PageLowerBound int DECLARE @PageUpperBound int DECLARE @Where VARCHAR = ' DECLARE  @Order VARCHAR = ' DECLARE @exsql NVARCHAR (+) = ' SET @PageLowerBound = @PageSize * (@PageIndex-1 ) Set @PageUpperBound = @PageSize-1 + @PageLowerBound--conditional SET @Where = ' Where 1=1 ' IF @verifyStat                        Us>=0--Conditional number Beginset @Where [email protected]+ ' and verifystatus = ' +cast (@verifyStatus as VARCHAR) END IF LEN (@citycode) >0 BEGIN SET @Where [email protected]+ ' and Startcitycode = ' +cast (@ci  Tycode as VARCHAR (+) + "' ENDIF LEN (@citycode) >0--Conditional string Beginset @Where [email protected]+ ' and city like '% ' +cast (@citycode asVARCHAR (+) + '% ' ' ENDIF LEN (@keywords) >0--Fuzzy query beginset @Where [email protected]+ ' and (' SET @Where [email  protected]+ ' teamname like '% ' +cast (@keywords as VARCHAR) + '% ' SET @Where [email protected]+ ' or Sloga n like '% ' +cast (@keywords as VARCHAR) + '% ' ' SET @Where [email protected]+ ') ' end--sort if @orderby =0beginset @O rder= n ' ORDER by isshowindex Desc, createtime desc ' endelse beginset @Order = n ' ORDER by isshowindex ASC, createtime ASC ' END-Creates a temporary table create table #data (RowNo int IDENTITY (0, 1) NOT NULL, keyidint NOT NULL) SET @exsql =n ' INSERT  Into #data (KeyID) SELECT teamid from T_team_teamlist ' [email protected] [Email protected]--select @exsql EXEC sp_executesql @exsqlSET @TotalCount = (select COUNT (1) from #data) SELECT * from dbo.t_team_teamlist T1 JOIN #data e O N t1. Teamid=e.keyid WHERE e.rowno >= @PageLowerBound and E.rowno <= @PageUpperBoundORDER by E.rowno ASC END
--The second simple point of the sub-industry create  PROC p_pc_getleavecommentslist    @pageindex int,    @pagesize int,    @TotalCount int Outputas    BEGIN        SELECT @TotalCount =count (0) from dbo.t_comm_leavecomments         ; With CTE as (SELECT RowNumber = Row_number () up (ORDER by Createts DESC), *    from  dbo.t_comm_leavecomments        ) C10/>select * from CTE         WHERE RowNumber between (@pageindex-1) * @pageSize + 1 and @pageindex * @pageSizeORDER by Ro Wnumber    END       

  

  

SQL Stored Procedure Paging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.