如果我刪除LIMIT "&PageStart&" , "&PageEnd&"
,則以下查詢正常工作。我從數據庫中獲取所有數據。但它不適用於LIMIT
和這兩個參數。我究竟做錯了什麼?SELECT未按預期工作
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "Driver={SQL Server}; Server=Localhost; Database=book-it-fifa;"
strSQL = "select distinct buchung_id, von, bis, abteilung, veranstalter, THEMA, THEMA_ENABLED " & _
" from RESERVIERUNGRAUM r " & _
" ,BUCHUNG b " & _
" where r.BUCHUNG_ID = b.ID " & _
" and von >= convert(date, getdate(), 4) " & _
" and von < convert(date, dateadd(day,1, GETDATE()), 4) " & _
" and BIS >= getdate() " & _
" and STORNO is null "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
If objRec.EOF Then
Response.write (" Not found record.")
Else
'**** Paging/Pagination Calculator ***'
Dim PageLen,PageNo,TotalRecord,TotalPage,intID
Dim PageStart,PageEnd
PageLen = 2
PageNo = Request.QueryString("Page")
if PageNo = "" Then PageNo = 1
TotalRecord = UBound(objRec.GetRows,2)+1
PageStart = ((PageLen*PageNo)-PageLen)
PageEnd = PageLen
If TotalRecord <= PageLen Then
TotalPage =1
ElseIf (TotalRecord Mod PageLen = 0) Then
TotalPage =(TotalRecord/PageLen)
Else
TotalPage =(TotalRecord/PageLen)+1
TotalPage = Cint(TotalPage)
End If
'*** Close Object and Open New RecordSet ***'
objRec.Close()
strSQL = strSQL & "ORDER BY von, bis ASC LIMIT "&PageStart&" , "&PageEnd&" "
objRec.Open strSQL, Conn, 1,3
會發生什麼? – RonaldBarzell
它也不能正常工作 – Paks
這個問題的另一個版本:http://stackoverflow.com/questions/10387386/equivalent-of-limit-in-t-sql – MatthewMartin