0

如果我删除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
4

1 回答 1

2

SQL Server 不支持 LIMIT。你可以在这里读更多关于它的内容:

http://channel9.msdn.com/Forums/Coffeehouse/102407-SQL-Server-and-LIMIT-clauses-on-SELECT-statements

于 2012-11-28T23:21:57.617 回答