RND查询可在Access中工作,但不能在ASP中工作

时间:2019-04-06 15:53:00

标签: vbscript asp-classic

我有一个简单的rnd查询,在Access中可以正常工作,但是当我在asp页上运行它时,每次都会得到完全相同的记录。我更新了原始帖子,以在ASP页和数据库连接中显示新的SQL。

访问权限:

SELECT TOP 1 tblPlayers.*
FROM tblPlayers
WHERE (((tblPlayers.FN) Like "*aaa*"))
ORDER BY Rnd([LID]);

ASP页(基于以下评论的反馈)

Dim sql, rssql

sql = "SELECT TOP 1 tblPlayers.* "
sql=sql & "FROM tblPlayers "
sql=sql & "WHERE (((tblPlayers.FN) Like '%aaa%')) "
sql=sql & "ORDER BY Rnd([LID]); "

set rssql = Server.CreateObject ("ADODB.RecordSet")
rssql.Open sql, conn 

数据库连接

<%
Dim conn 
set conn=Server.CreateObject("ADODB.Connection") 
conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/_db/database.mdb") & ""
%>

如果有人有任何建议,请告诉我。谢谢!

1 个答案:

答案 0 :(得分:1)

尝试

sql = "SELECT TOP 1 tblPlayers.* "
sql=sql & "FROM tblPlayers "
sql=sql & "WHERE (((tblPlayers.FN) Like '%aaa%')) "
sql=sql & "ORDER BY NewId(); "

https://www.petefreitag.com/item/466.cfm