zoukankan      html  css  js  c++  java
  • 一个分页sql语句生成的function

            '==============================
            ''分页sql语句生成代码
            '==============================

            Function GetPageSql(TblName, FldName, PageSize, PageIndex, OrderType, StrWhere)
                    Dim StrTemp, StrSql, StrOrder
                    ''根据排序方式生成相关代码
                    If OrderType = "Asc" Then
                            StrTemp = "> (Select Max([" & FldName & "])"
                            StrOrder = " Order By [" & FldName & "] Asc"
                    Else
                            StrTemp = "< (Select Min([" & FldName & "])"
                            StrOrder = " Order By [" & FldName & "] Desc"
                    End If

                    ''若是第1页则无须复杂的语句
                    If PageIndex = 1 Then
                            StrTemp = ""
                            If StrWhere <> "" Then
                                    StrTemp = " Where " & StrWhere
                            End If
                            StrSql = "Select Top " & PageSize & " * From [" & TblName & "]" & StrTemp & StrOrder
                    Else
                            ''若不是第1页,构造sql语句
                            StrSql = "Select Top " & PageSize & " * From [" & TblName & "] Where [" & FldName & "]" & StrTemp & _
                                     " From (Select Top " & (PageIndex -1) * PageSize & " [" & FldName & "] From [" & TblName & "]"
                            If StrWhere <> "" Then
                                    StrSql = StrSql & " Where " & StrWhere
                            End If
                            StrSql = StrSql & StrOrder & ") As Tbltemp)"
                            If StrWhere <> "" Then
                                    StrSql = StrSql & " And " & StrWhere
                            End If
                            StrSql = StrSql & StrOrder
                    End If
                    ''返回sql语句
                    GetPageSql = StrSql
            End Function

    如何使用
            Dim StrWhere:StrWhere = ""    'where条件
            Set rs = server.CreateObject("adodb.recordset")
            sql = GetPageSql("表名","无重复值的排序字段名",每页记录数,当前页,"desc",StrWhere )
            rs.Open sql, conn, 1, 1

  • 相关阅读:
    MFC 时钟 计算器 日期天数计算
    test10
    test9
    iOS 防止按钮快速点击造成多次响应的避免方法
    NSBundle读取图片 plist文件和txt文件
    按指定格式的子字符串,删除和分割字符串
    python批处理入门知识点
    命令行ffmpeg批量旋转视频
    NSData转化成十六进制字符串
    xcode里面使用Memory Leaks和Instruments检测内存泄漏
  • 原文地址:https://www.cnblogs.com/MaxIE/p/720719.html
Copyright © 2011-2022 走看看