Copy Code code as follows:
/*
Date: 2009-03-19
Function: Get the Game country task list data according to various conditions
*/
Create procedure [dbo]. [Prgs_nation_task_getlist]
@PageSize int = 100--Displays the number of record bars per page, defaults to 100
@PageIndex int = 1,--current fetch page number to display, default is 1, database returns one page of data based on Pagesize,pageindex calculation
@RetTotal int output,--Total number of records
@RetCount int output,--Returns the number of records
@RetPageIndex int output,--Print current page number
@ReturnDesc varchar (128) Output--Returns the description of the operation result
As
Begin
SET NOCOUNT ON
Set XACT_ABORT on
Set @RetTotal = 0
Set @RetCount = 0
Set @RetPageIndex = @PageIndex
--Multi-condition value
DECLARE @Err INT--Error
DECLARE @PageCount INT--Total pages
DECLARE @BeginRID INT--Start the Rid
DECLARE @MaxRow INT--Last line
Select @RetTotal = COUNT (*)
From Nationtask
Select @Err = @ @ERROR
If @Err <> 0
Begin
Set @ReturnDesc = ' Extract the total number of national tasks failed! '
Return-1
End
--Returns an empty result set if no data is available
If @RetTotal = 0
Begin
Set @ReturnDesc = ' current condition has no national task record! '
Return 1
End
--Calculate Total pages
Set @PageCount = @RetTotal/@PageSize
If @RetTotal% @PageSize > 0
Begin
Set @PageCount = @PageCount + 1
End
--Returns an empty result set if the total number of pages is exceeded
If @PageIndex > @PageCount
Begin
Set @ReturnDesc = ' current condition has no national task record! '
Return 1
End
--Gets the Rid of the first row of records to return the page
Set @MaxRow = @PageSize * (@PageIndex-1) + 1
SET ROWCOUNT @MaxRow
Select @BeginRID = Rid
From Nationtask
ORDER BY Rid Desc
--return list of data
SET ROWCOUNT @PageSize
Select Rid
, TaskName
, Tasktitle
, imageID
, effectid
, StartTime
From Nationtask
where Rid <= @BeginRID
ORDER BY Rid Desc
Set @RetCount = @ @rowcount
--End
Set @ReturnDesc = ' Extract national Task List success! '
Return 1
End