分頁|資料|語句 1<%@Language = "VBScript" Codepage = "936"%>
2<%
3'分頁sql語句產生代碼
4Function GetPageSql(TblName,FldName,PageSize,PageIndex,OrderType,StrWhere)
5 Dim StrTemp,StrSql,StrOrder
6 '根據排序方式產生相關代碼
7 If OrderType = 0 Then
8 StrTemp = "> (Select Max([" & FldName & "])"
9 StrOrder = " Order By [" & FldName & "] Asc"
10 Else
11 StrTemp = "< (Select Min([" & FldName & "])"
12 StrOrder = " Order By [" & FldName & "] Desc"
13 End If
14
15 '若是第1頁則無須複雜的語句
16 If PageIndex = 1 Then
17 StrTemp = ""
18 If StrWhere <> "" Then
19 Strtmp = " Where " & StrWhere
20 End If
21 StrSql = "Select Top " & PageSize & " * From [" & TblName & "]" & Strtmp & StrOrder
22 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 <> "" Then
26 StrSql = StrSql & " Where " & StrWhere
27 End If
28