乙個分頁sql語句生成的function

2021-09-05 16:18:03 字數 1578 閱讀 5928

'******************************

''分頁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

乙個非常好的ORACLE的分頁SQL語句

select from select my table.rownum as my rownum from select yhbh,yhmc from yysf tb yonghxx order by yhbh my table where rownum 20 where my rownum 10 其...

乙個不會的SQL語句

12.有兩個表a 和b 均有key 和value 兩個字段,如果b 的key 在a 中也有,就把b 的value 換為a 中對應的value 這道題的sql 語句怎麼寫?update b set value select value from awhere a.key b.key where exi...

乙個神奇的SQL語句

題目是這樣的 分別往這兩張表中新增3條資料。查詢營業額最高商家的商品總價與營業額最低商家的商品總價差是多少 5分 create view vm2 as select price limit num as total money b.id from business b,goods g where b...