Create Proc Turnpage
@QCOLS VARCHAR (200), - Columns need to query
@QTables VARCHAR (200), - Tables and conditions for queries
@IKey Varchar (20), - Logo field
@oKey Varchar (20), - Sort field
@PageSize Int, - Row number of rows per page
@PAGENUMBER INT - Page number to display, starting from 0
AS
Set nocount on
Begin
Declare @sqltext as varchar (1000)
Declare @sqltable as varchar (1000)
Set @sqltable = 'SELECT TOP' CAST ((@ PAGENUMBER 1) * @Pagesize As Varchar (30)) '' @Qcols 'from' @QTables 'Order By
' @ OKEY ' DESC '
Set @sqltext =
'SELECT TOP' CAST (@PageSize As Varchar (30)) '*'
'From (' @sqltable ') as Tablea'
'WHERE' @IKey 'Not in (SELECT TOP'
Cast (@PAGENUMBER * @PageSize As Varchar (30)) '' @IKey
'From (' @Sqltable ') as tableb)'
Exec (@sqltext)
--Print (@sqltext)
End
Go