Copy CodeThe code is as follows:
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
CREATE PROCEDURE [dbo]. [Pagination]
@Page int = 1,--current page number
@PageSize int = 10--Number of record bars per page (page size)
@Table nvarchar (500)--table name or view name, or even nested sql: (Select * from Tab Where id>1000) tab
@Field nvarchar (800) = ' * ',--Returns the recordset field name, "," is separated by the default is "*"
@OrderBy nvarchar = ' ID ASC ',--collation
@Filter nvarchar (500),--Filtration conditions
@MaxPage smallint output,--execution result-1 error, 0 false, Maxpage true
@TotalRow int output,--Total Records/* 2007-07-12 22:11:00 Update * *
@Descript varchar OUTPUT--Result description
As
BEGIN
-- =============================================
--Author:Jimmy.Yu
--Create date:2007-5-11
--Description:sql more than 2005 version of common paging stored procedures
-- =============================================
Set rowcount @PageSize;
Set @Descript = ' successful ';
-------------------parameter Detection----------------
IF LEN (RTRIM (LTRIM (@Table))!> 0
Begin
Set @MaxPage = 0;
Set @Descript = ' table name is empty ';
return;
End
IF LEN (RTRIM (LTRIM (@OrderBy))!> 0
Begin
Set @MaxPage = 0;
Set @Descript = ' order is empty ';
return;
End
IF ISNULL (@PageSize, 0) <= 0
Begin
Set @MaxPage = 0;
Set @Descript = ' page size error ';
return;
End
IF ISNULL (@Page, 0) <= 0
Begin
Set @MaxPage = 0;
Set @Descript = ' page error ';
return;
End
-------------------End of Detection----------------
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.