High-efficiency jsp + mssql Stored Procedure Common Database Paging

Source: Internet
Author: User

High-efficiency jsp + mssql Stored Procedure Common Database Paging

High-efficiency jsp tutorial + mssql Stored Procedure general database tutorial page

Create procedure Ture_Page

@ PageSize int, -- number of rows per page
@ PageIndex int, -- 1 indicates the first page
@ Col varchar (200), -- the field to be displayed
@ Table varchar (200), -- the Table used. If there are multiple entries, the content between the from and where is written.
@ Where varchar (200) = '', -- conditions used
@ OKey varchar (50), -- Sort Field
@ Order varchar (20) = 'asc '-- sorting method

As
Declare @ brief STR varchar (2000)
Set nocount on

Set @ override STR = 'select top'
Set @ brief STR = @ brief STR + convert (nvarchar, @ PageSize)
If @ Order = 'desc' and @ PageIndex> 1
Set @ brief STR = @ brief STR + ''+ @ Col + 'from' + @ Table + 'where' + @ OKey + '<'
Else if @ PageIndex = 1
Set @ brief STR = @ brief STR + ''+ @ Col + 'from' + @ Table + 'where' + @ OKey + '> ='
Else
Set @ brief STR = @ brief STR + ''+ @ Col + 'from' + @ Table + 'where' + @ OKey + '>'
If @ PageIndex> 1
Begin
If @ Order = 'asc'
Set @ brief STR = @ brief STR + '(select max (' + @ OKey + ') from (select top'
Else
Set @ brief STR = @ brief STR + '(select min (' + @ OKey + ') from (select top'
Set @ brief STR = @ brief STR + convert (nvarchar, (@ PageIndex-1) * @ PageSize)
Set @ brief STR = @ brief STR + ''+ @ OKey + 'from' + @ Table + 'ORDER BY' + @ OKey +'' + @ order + ') as t )'
End
Else
Set @ brief STR = @ brief STR + '0'
If @ Where <>''
Set @ brief STR = (@ brief STR + 'and' + @ Where + 'ORDER BY' + @ OKey + ''+ @ order)
Else
Set @ brief STR = (@ brief STR + 'ORDER BY' + @ OKey + ''+ @ order)

Print @ brief Str
Exec (@ brief Str)
Set nocount off
GO %>

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.