Two efficient ASP paging functions

Source: Internet
Author: User
Tags add count empty end functions sql sort access
Two efficient ASP paging functions (Statistics records, paging extraction Records)

<%
'    /* Smart return Paging SQL statement */
'    ///<summary>
'     Function: Intelligent return paging SQL statement
'    ///</summary>
'    ///<param name= ' PrimaryKey "> Primary key (cannot be empty) </param>
'    ///<param name= ' queryfields ' > Extract field (cannot be empty) </param>
'    ///<param name= "tablename" > table (theoretically allow multiple tables) </param>
'    ///< param name= "condition" > Conditions (Nullable) </param>
'    ///<param name= ' ORDER by ' > Sort, Format: Field name + " "+asc (Nullable) </param>
'    ///<param name= ' pageSize ' > pagination (cannot be empty) </param>
'    ///<param name= "pageIndex" > Current page starting from: 1 (cannot be empty) </param>
'    ///< Returns></returns>
Public Function getpagelistsql (primarykey,  queryfields,  tableName,   condition,  orderby,  pagesize,  pageIndex)

Dim strtmp,sqlselect,sqlprimarykeyselect,strorderby,strwhere,strtop,pageindexsize
 strTmp= "
'//- --STRTMP The SQL statement used to return
 sqlselect = "
 sqlprimarykeyselect ="
 strorderby = "
  strwhere = "where 1=1"
 strtop = ""
 pageindexsize = 0

'        //0: Paging quantity
'        //1: Extract Field
'        //2: Table
'        //3: Condition
'        //4: Record for primary key not present
'        //5: Sort
        sqlselect = ' select top {0} {1} ' {2} {3} {4} {5} '
  ' &NBSP;&N bsp;    //0: Primary key
  '       //1:top number, for pagination * (sort number-1)
  '       //2: Table
  '       //3: Conditions
  '       //4: Sort
        Sqlprimarykeyselect = "and {0}" (select {1} {0} from {2} {3} {4}) "

        If by <> "then
             Strorderby = "ORDER By" &orderby
            End If
     if condition <> "then
             strwhere =strwhere& "and" &condition
          pageindexsize = (pageIndex-1) * PageSize
           End If
      if CInt (pageindexsize) > 0 Then
    & nbsp; 
            strtop = "Top" & Pageindexsize

Sqlprimarykeyselect = replace (replace (replace (Sqlprimarykeyselect, {0}, PrimaryKey), ' {1} ', Strtop ), "{2}", TableName), "{3}", strwhere), "{4}", Strorderby)

strtmp = replace (replace (replace (Sqlselect, {0}, pageSize), ' {1} ', queryfields), ' {2} ', TableName), "{3}", strwhere), "{4}", Sqlprimarykeyselect), "{5}", Strorderby)


Else
strtmp = replace (replace (replace (Sqlselect, {0}, pageSize), ' {1} ', queryfields), ' {2} ', TableName), "{3}", strwhere), "{4}", ""), "{5}", Strorderby)


End If
Getpagelistsql= strtmp


End Function

' * * Paging query data records Total Access *
'///<summary>
'///function: Paging query data records Total Access
'///</summary>
'///<param name= ' ptbname >----The connection of the table or tables to be displayed </param>
'///<param name= ' PID > Primary key </param> for primary table----
'///<param name= ' pstrcondition ' >----query conditions, do not need to where</param>
'///<param name= ' pdist >----Add Query field DISTINCT default 0 not Add/1 add </param>
'///<returns></returns>
Public Function getpagelistcounts (PID, Ptbname, Pstrcondition, Pdist)

'//---a query that holds the total number of query results
'//---SQL construction of queries containing distinct
'//---The SQL construction of the total number of queries containing distinct
Dim strtmp,sqlselect,sqlcounts
strtmp = ""
Sqlselect = ""
Sqlcounts = ""

If CInt (pdist) = 0 Then

Sqlselect = "Select"
sqlcounts = "COUNT (*)"

Else

Sqlselect = "Select DISTINCT"
sqlcounts = "COUNT (DISTINCT & pid&)"
End If
If pstrcondition = "" Then

strtmp = Sqlselect & "" & Sqlcounts & "from" & Ptbname & ""

Else

strtmp = Sqlselect & "" & Sqlcounts & "from" & ptbname& "Where (1=1) and" & Pstrcondition
End If

getpagelistcounts= strtmp

End Function

%>



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.