Friday, July 14, 2006

SELECT random records from a database

asp script:
randomize
sql="select max (ID) as maxid from table"rs.open sql,cn
max=rs("maxid")
rs.close

for i=0 to 100
rndNum=int(rnd()*max)+1
idstr=idstr&rndNum&","
next
idstr=idstr+"0"

sql="select top 25 ID, * from table where ID in ("+idstr+")"
rs.open sql,cn



<% randomize sql="select max (ID) as maxid from table" rs.open sql,cn max=rs("maxid") rs.close for i=0 to 100 rndNum=int(rnd()*max)+1 idstr=idstr&rndNum&"," next idstr=idstr+"0" sql="select top 25 ID, * from table where ID in ("+idstr+")" rs.open sql,cn %>

No comments: