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
-Multiple conditional values
declare @Err INT--Error
Declare @PageCount INT--Total pages
Declare @BeginRID INT--Start row Rid
DECLARE @MaxRow INT--Last line
Select @RetTotal = count (*)
from nationtask
Select @Err = @ @ERROR
If @Err <> 0
Begin
Set @ReturnDesc = ' Extract total number of national tasks failed! '
return-1
End
--if there is no data, returns an empty result set
If @RetTotal = 0
Begin
Set @ReturnDesc = ' current condition has no national task record! '
return 1
End
-count total pages
Set @PageCount = @RetTotal/@PageSize
If @RetTotal% @PageSize > 0 begin
Set @PageCount = @PageCount + 1
End
--more than the total number of pages, returns an empty result set
if @PageIndex > @PageCount
Begin
Set @ReturnDesc = ' current condition has no national task record! '
return 1
End
--Gets the Rid
Set @MaxRow = @PageSize * (@PageIndex-1) + 1
Set Rowcoun for the first row of records to be returned to the page T @MaxRow
Select @BeginRID = Rid
from nationtask
ORDER by rid Desc
--Returns the list of data
SET ROWCOUNT @PageSize
Select Rid
, TaskName
, Tasktitle
, imageID
, effectid
, StartTime the
from Nationtask
where rid <= @BeginRID the
ORDER by Rid desc
Set @RetCount = @ @rowcount
--end
Set @ReturnDesc = ' Extract national Task list successfully! '
return 1
End