2015-02-04 62 views
0

所以我在SQL中有這個查詢。我知道如果記錄是最後一個記錄集:如何知道記錄是否最後

sql = SELECT * FROM table WHERE RID = 27 
Set rs=Conn.Execute(sql) 

If not rs.EOF Then 

    iID = rs("RID") 
    If iID = LAST Then response.write ("this is last record") End If 

End If 
Conn.Close 
Set Conn = Nothing 

任何方式來做到這一點?

回答

3

不知道爲什麼你需要做到這一點,但你可以做這樣的事情:

sql = SELECT * FROM table WHERE RID = 27 
Set rs=Conn.Execute(sql) 

If not rs.EOF Then 

    rs.MoveNext 
    If rs.EOF Then 
     response.write ("this is last record") 
    End If 

End If 
Conn.Close 
Set Conn = Nothing 

鑑於你查詢的性質,它看起來像你將只能得到1列反正所以這似乎是一種毫無意義的。

+0

我明白你的意思了。此頁面是我的詳細信息頁面。所以你是對的,查詢返回1行。我仍然可以使用您的示例來了解此記錄是否是表格中的最後一條記錄? – Brasciole

+1

當然,但就像我說過,如果只有1行,爲什麼還要額外的代碼?儘管你可以在循環中使用同樣的東西。 –

+0

你在哪裏插入rs.MoveNext?在設置rs-Conn.Execute(sql)行後: – Brasciole

0
<% 
sql = "SELECT MAX(RID) FROM table " 
Set rs=Conn.Execute(sql) 

isLast = "no records" 
If not rs.BOF Then 
if rs(0) = 27 then '' 27 or somone else for your taste 
    ifLast = "last record" 
else 
    ifLast = "not last record" 
end if 
End If 

Response.Write isLast 

Conn.Close 
Set Conn = Nothing 
%> 
相關問題