如何向后单步执行 ASP 经典 for 循环?

How to step through ASP classic for loop backwards?

我仅从该查询中检索 10 个最新结果,这导致它们从最新到最旧排序,但我希望它们从最旧到最新显示。我尝试使用子选择查询来执行此操作,但在执行此操作时无法正确检索结果。现在我正试图通过像这样

这样的循环向后退一步来做到这一点
for i=ubound(arr,2) to 0 step -1

这仍在遍历从 0 到最后一个元素的数组,因为正在创建的图表仍在显示降序日期元素。我该如何解决这个问题,或者有更好的方法来解决这个问题?谢谢!

Dim data()
    Redim data(doccount)
    label=""
    strSQL = "Select TOP 10 DATEPART(m, thedate),DATEPART(d, thedate),DATEPART(yyyy, thedate),DATEPART(hh, thedate),DATEPART(mi, thedate), servicestatus from [ServiceUptime] order by thedate desc"
    'Response.write(strSQL)
    Set rs = objConnection.Execute(strSQL, ,adCmdText)
    if not (rs.bof or rs.eof) then
        arr = rs.getrows()
        ''Create Data set
        for i=0 to ubound(arr,2)
            if i = ubound(arr,2) then
                for j=0 to doccount
                    data(j) = data(j) &"["& i &","& arr(j+5,i) &"]"
                next
            else
                for j=0 to doccount
                    data(j) = data(j) &"["& i &","& arr(j+5,i) &"],"
                next
            end if
        next
        ''Create x axis Labels
        if ubound(arr,2)>9999 then
            ''There are too many points
            ''Attempt to only use 5
            Response.write(ubound(arr,2))
            unit = Round(ubound(arr,2)/5,0)
            for c = 0 to unit*5 Step unit
                label = label   &"["& c &",'"& monthArr(arr(0,c)) &" "& arr(1,c) &", "& arr(2,c) &", "& arr(3,c) &"':"& arr(4,c) &"'],"
            next

        else
            ''There are not enough points.
            ''Use them all

            for i=ubound(arr,2) to 0 step -1
                if i = 0 then
                    label = label   &"["& i &",'"& monthArr(arr(0,i)) &" "& arr(1,i) &" "& arr(2,i) &" "& arr(3,i) &":"& arr(4,i) &"']"
                else
                    label = label   &"["& i &",'"& monthArr(arr(0,i)) &" "& arr(1,i) &", "& arr(2,i) &" "& arr(3,i) &":"& arr(4,i) &"'],"
                end if
            next
        end if

        ''Create mouse over labels
        moLabel = "moArr = new Array(" & ubound(arr,2) & ");"
        for i=ubound(arr,2) to 0 step -1
            moLabel = moLabel & "moArr[" & i & "]='" & monthArr(arr(0,i)) &" "& arr(1,i) &", "& arr(2,i) &", "& arr(3,i) &":"& arr(4,i) &"';"
        next
    else
        dateNow = Date
        dateYest = DateAdd("d",-1,dateNow)
        for j=0 to doccount
            data(j) =  "[0,0],[1,0]"
        next
        label = "[0,'"&monthArr(DatePart("m",dateNow))&" "&DatePart("d",dateNow)&", "&DatePart("yyyy",dateNow)&"'][1,'"&monthArr(DatePart("m",dateYest))&" "&DatePart("d",dateYest)&", "&DatePart("yyyy",dateYest)&"']"
        moLabel = "moArr = new Array(2); moArr[0]='" & monthArr(DatePart("m",dateNow))&" "&DatePart("d",dateNow)&", "&DatePart("yyyy",dateNow) &"';"& "moArr[0]='" & monthArr(DatePart("m",dateYest))&" "&DatePart("d",dateYest)&", "&DatePart("yyyy",dateYest) &"';"
    end if

尝试使用子查询:

SELECT TOP 10 * FROM (
   SELECT DATEPART(m, thedate),DATEPART(d, thedate),DATEPART(yyyy, thedate),DATEPART(hh, thedate),DATEPART(mi, thedate), servicestatus 
   FROM [ServiceUptime] 
   ORDER BY thedate DESC)