Database Paging Stored Procedures

Source: Internet
Author: User
Stored Procedures | pagination | data | database/*
Database paging stored Procedure---equn.net
Parameter description:
? tablename for Search table name
? Where is the search table name, to display all records please set to "1=1"
? By-order for search results, such as ORDER by id DESC
? curpage Current Page number
? Page_record the number of record bars per page
Results:
? Returns the Page_record record of page curpage in table tablename that satisfies the condition where the result is sorted by order
*/
CREATE PROCEDURE xp_page (@tablename varchar (), @where varchar (m), @orderby varchar (+), @curpage int, @page_record int
? as
Begin
? declare @cmd varchar (500)
? declare @uprecord int
? Set @uprecord = @curpage * @page_record
? set @cmd = ' Select Top ' +cast (@page_record as char) + ' * from ' + @tablename + ' where ' + @where + ' and ID not in (select Top ' +ca St (@uprecord as char) + ' ID from ' + @tablename + ' where ' + @where + ' + @orderby + ') ' + @orderby
? EXEC (@cmd)
End
Go

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.