|
ALTER PROCEDURE [dbo]. [PageList]
(
@PageSize int,-records per page
@PageIndex int,-the current number of pages, starting at 1
@Condition varchar (8000),-query conditions, including and, where, must have a condition such as where 2> 1
@TheTable varchar (8000), --table name
@SelectField varchar (8000),-the field to be selected
@OrderBy varchar (8000), --OrderBy, including order
@TableID varchar (8000) --table primary key
)
AS
begin
declare @Sql varchar (8000)
--Return record
set @ Sql = 'select top' + cast (@PageSize as varchar (10)) + '' + @SelectField + 'from' + @TheTable + '' + @Condition + 'and'
+ @TableID + 'not in (select top' + cast ((@ PageSize * (@ PageIndex-1)) as varchar (10)) + '' + @ TableID + 'from' + @TheTable + '' + @Condition
+ '' + @OrderBy + ')' + @OrderBy
exec (@sql)
--- return total
set @ Sql = 'select count (' + @TableID + ') from' + @TheTable + '' + @Condition
exec (@sql)
end
Call this stored procedure, and return the recordset and number of records! Weep! !! !! !! !! !! 1 |
|