Create proc test_2_sp_pageview
@ Tbname sysname, -- Name of the table to be displayed by PAGE
@ Fieldkey sysname, which is used to locate the record's primary key (unique key) field and can only be a single Field
@ Pagecurrent Int = 1, -- the page number to be displayed
@ Pagesize Int = 10, -- size of each page (number of records)
@ Fieldshow nvarchar (1000) = '', -- List of fields to be displayed separated by commas (,). If this parameter is not specified, all fields are displayed.
@ Fieldorder nvarchar (1000) = '', -- List of sorting fields separated by commas (,). You can specify DESC/ASC after a field.
@ Where nvarchar (1000) = '', -- Query Condition
@ Pagecount int output -- total number of pages
As
Declare @ SQL nvarchar (4000)
Set nocount on
-- Check whether the object is valid
If object_id (@ tbname) is null
Begin
Raiserror (n' object "% s" does not exist ', @ tbname)
Return
End
If objectproperty (object_id (@ tbname), N 'istable') = 0
And objectproperty (object_id (@ tbname), N 'isview') = 0
And objectproperty (object_id (@ tbname), n'istablefunction') = 0
Begin
Raiserror (n' "% s" is not a table, view, or table value function ', @ tbname)
Return
End
-- Paging field check
If isnull (@ fieldkey, n'') =''
Begin
Raiserror (n' primary key (or unique key) required for paging processing)
Return
End
-- Other parameter checks and specifications
If isnull (@ pagecurrent, 0)
Previous:Stored Procedure of SQL Server paging (available for test and available for sorting pages of non-dimension One-value fields)
Next article:SQL Server paging stored procedures (available for test and available for sorting pages of non-dimension One-value fields) are the most active, with poor performance