The SQL Server paging Stored Procedure (tested and available, with non-dimension One-Value Field sorting paging) is faster.

Source: Internet
Author: User
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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.