如果我删除LIMIT "&PageStart&" , "&PageEnd&"
,则下面的查询正常。我从数据库中获取所有数据。但它不适用于LIMIT
和这两个参数。我做错了什么?
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
答案 0 :(得分:2)
SQL Server不支持LIMIT。你可以在这里阅读更多相关信息:
http://channel9.msdn.com/Forums/Coffeehouse/102407-SQL-Server-and-LIMIT-clauses-on-SELECT-statements