随机提取10条记录的例子:Sql server:select top 10 * from 表 order by newid()Access:SELECT top 10 * FROM 表 ORDER BY Rnd(id) Rnd(id) 其中的id是自动编号字段,可以利用其他任何数值来完成比如用姓名字段(UserName)SELECT top 10 * FROM&nbs...
http://www.jb51.net//article/630.htm
代码如下:本文相关代码如下:Access:selecttopn*fromtableorderbyrnd(id)'id为数据库的自动编号字段SqlServer:selecttopn*fromtableorderbynewid()但在ASP+Access中,或许是因为缓存的原因,第一条SQL语句无法得到预期的结果,而VB+Access则可以。解决办法是改用如下SQL语句: 本文相关代码如下:RandomizesSqlTxt="Selecttop10*FromTaborderbyrnd(-(id+"&rnd()&"))"...
http://www.jb51.net//article/373.htm
<%'Movingtorandomrecord-StevenJones'ExtensionIfNot(记录集名称.bofand记录集名称.eof)Then'resetthecursortothebeginningIf(记录集名称.CursorType>0)Then记录集名称.MoveFirstElse记录集名称.RequeryEndIf记录集名称_totalrn=-1记录集名称_totalrn=记录集名称.RecordCount'onyworksonsomerecordsets,butmuchfasterIf(记录集名称_totalrn=-1)Then'andifitdidn'tw...
http://www.jb51.net//article/100.htm
前两天看到有人要编个考试系统,当时只是简单回了下用随机函数RND 实际一般需要从数据库中随机提取N道题目。 以下代码都基于VBS; 通常的编写类似这样的'产生不重复随机数functionrndarray(istart,iend,sum)dimarrayid(),i,j,blnre,temp,iloop,eloopredimarrayid(sum-1)i=0iloop=0eloop=0blnre=falserandomizedowhilei<sumtemp=int(rnd*(iend-istart+1)+istart)ifi=0thenarrayid(0)=tempi=i+1iloo...
http://www.jb51.net//article/9.htm
