. NET SQL Server paging stored procedures

Source: Internet
Author: User

Create PROCEDURE [dbo]. [Proc_splitpage]
@tblName varchar (255),--table name
@strFields varchar (1000) = ' * ',--the column that needs to be returned, default *
@strOrder varchar (255) = ',--sort field name, required
@strOrderType varchar = ' ASC ',--sort the way, default ASC
@PageSize int = 10,--page size, default 10
@PageIndex int = 1,---page number, default 1
@strWhere varchar (1500) = "--Query criteria (note: Do not add where)
As

DECLARE @strSQL varchar (5000)

If @strWhere! = "
Set @strWhere = ' where ' [email protected]

Set @strSQL =
' SELECT * FROM (' +
' SELECT row_number () over (ORDER by ' [email protected]+ ' [email protected]+ ') as POS, ' [email protected]+ ' +
' From ' [email protected]+ ' [email protected]+
') as SP WHERE pos between ' +str ((@PageIndex-1) * @PageSize + 1) + ' and ' +str (@PageIndex * @PageSize)

EXEC (@strSQL)

. NET SQL Server paging stored procedures

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.