SQL Server Stored Procedure paging

Source: Internet
Author: User

One: Stored procedure implementation Paging Example: Query the property list ALTER procedure [dbo]. [Bm_getblocklist] @pageIndexint,-------number of pages @pagesizeint,---------number of bars displayed @cityidint asdeclare @sql nvarchar (max), @sql2 nvarchar (max)Set@sql ='From Agentrecmd_block ABLeft joins Base_block BLOCK on AB. Blockid=block. row_id left joins Base_area area on BLOCK. area_id=Area . row_id left JOIN base_district DIS in area. region_id=DIS. Row_id left joins Base_city city on DIS. city_id=City . ROW_IDwhereBlock. gcflag=0and block.is_approve=0and AB. gcflag=0and City . ROW_ID='+convert (nvarchar), @cityId) +'and block. isapp=1 '                 Set@sql2 ='Select Top'+ CONVERT (nvarchar ( $), @PageSize) +'block. ROW_ID, block. Block_name,dis. District_name,block. Avg_price_web,block. Hot_view_web,block. Housing_propery,ab. EndTime'+@sql+'and AB. row_id not in (select top'+convert (nvarchar ( $), (@pageIndex-1) * @PageSize) +'AB. ROW_ID'[Email protected]+'ORDER by AB. EndTime)'EXEC (@sql2);

Related Article

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.