1
<%@Language = "VBScript" Codepage = "936"%>2
<%3
'分页sql语句生成代码4
Function GetPageSql(TblName,FldName,PageSize,PageIndex,OrderType,StrWhere)5
Dim StrTemp,StrSql,StrOrder6
'根据排序方式生成相关代码7
If OrderType = 0 Then8
StrTemp = "> (Select Max([" & FldName & "])"9
StrOrder = " Order By [" & FldName & "] Asc"10
Else11
StrTemp = "< (Select Min([" & FldName & "])"12
StrOrder = " Order By [" & FldName & "] Desc"13
End If14
15
'若是第1页则无须复杂的语句16
If PageIndex = 1 Then17
StrTemp = ""18
If StrWhere <> "" Then19
Strtmp = " Where " & StrWhere20
End If21
StrSql = "Select Top " & PageSize & " * From [" & TblName & "]" & Strtmp & StrOrder22
Else '若不是第1页,构造sql语句23
StrSql = "Select Top " & PageSize & " * From [" & TblName & "] Where [" & FldName & "]" & StrTemp & _24
" From (Select Top " & (PageIndex-1) * PageSize & " [" & FldName & "] From [" & TblName & "]"25
If StrWhere <> "" Then26
StrSql = StrSql & " Where " & StrWhere27
End If28
StrSql = StrSql & StrOrder & ") As Tbltemp)"29
If StrWhere <> "" Then30
StrSql = StrSql & " And " & StrWhere31
End If32
StrSql = StrSql & StrOrder33
End If34
GetPageSql = StrSql '返回sql语句35
End Function36
Response.Write(GetPageSql("Message","MessageID",10,1,0,""))37
%>