Jimmy
Fri Sep 08 10:24:59 CDT 2006
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01C6D339.6B9AEDF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
thanks... few questions though. here is the code:
<%=20
Randomize()=20
randNum =3D (CInt(1000 * Rnd) + 1) * -1=20
=20
set conn =3D CreateObject("ADODB.Connection")=20
=20
sql =3D "SELECT TOP 1 cols," & _=20
"r =3D Rnd(" & randNum & ")" & _=20
"FROM TableName " & _=20
"ORDER BY r"=20
=20
set rs =3D conn.execute(sql)=20
=20
response.write rs(0)=20
=20
' ...=20
rs.close: set rs =3D nothing=20
conn.close: set conn =3D nothing=20
%>
what will randNum equal? a number between what and what?
in the SQL statement, what is "cols"? and "r"?
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in =
message news:ODk1Cb10GHA.4452@TK2MSFTNGP02.phx.gbl...
> =
http://databases.aspfaq.com/database/how-do-i-retrieve-a-random-record.ht=
ml
>=20
>=20
>=20
> "Jimmy" <j@j.j> wrote in message=20
> news:OreY4Y10GHA.4108@TK2MSFTNGP04.phx.gbl...
>> ill have a database with 1 table and 3 fields:
>>
>> ID FIRSTNAME LASTNAME
>>
>> (the ID field will be the auto incrementing index)
>>
>> there might be 10 records in the DB, there might be 10,000.
>> i need to open the DB and randomly select a record (and then display =
the=20
>> name, which i dont have a problem with)
>> how can i randomly select a record? im guessing id have to open a=20
>> recordset and check the count to get the number of records, so lets =
say=20
>> there were 100 records. i imagine i would have to generate a random =
number=20
>> between 1 and 100....
>>
>> anyone have a small example?
>>
>>=20
>=20
>
------=_NextPart_000_0012_01C6D339.6B9AEDF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2963" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>thanks... few questions though. here is =
the=20
code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff =
size=3D1><STRONG><% <BR> =20
Randomize() <BR> randNum =3D (CInt(1000 * Rnd) + 1) *=20
-1 <BR> <BR> set conn =3D=20
CreateObject("ADODB.Connection") <BR> <BR> sql =
=3D "SELECT=20
TOP 1 cols," & _ <BR> "r =3D Rnd(" =
&=20
randNum & ")" & _ <BR> "FROM =
TableName "=20
& _ <BR> "ORDER BY=20
r" <BR> <BR> set rs =3D =20
conn.execute(sql) <BR> <BR> response.write=20
rs(0) <BR> <BR> ' ... <BR> =
rs.close:=20
set rs =3D nothing <BR> conn.close: set conn =3D=20
nothing <BR>%></STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>what will randNum equal? a number =
between what and=20
what?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>in the SQL statement, what is "cols"? =
and=20
"r"?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>"Aaron Bertrand [SQL Server MVP]" =
<</FONT><A=20
href=3D"mailto:ten.xoc@dnartreb.noraa"><FONT face=3DArial=20
size=3D2>ten.xoc@dnartreb.noraa</FONT></A><FONT face=3DArial =
size=3D2>> wrote in=20
message </FONT><A =
href=3D"news:ODk1Cb10GHA.4452@TK2MSFTNGP02.phx.gbl"><FONT=20
face=3DArial =
size=3D2>news:ODk1Cb10GHA.4452@TK2MSFTNGP02.phx.gbl</FONT></A><FONT=20
face=3DArial size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>> =
</FONT><A=20
href=3D"
http://databases.aspfaq.com/database/how-do-i-retrieve-a-random-r=
ecord.html"><FONT=20
face=3DArial=20
size=3D2>
http://databases.aspfaq.com/database/how-do-i-retrieve-a-random-=
record.html</FONT></A><BR><FONT=20
face=3DArial size=3D2>> <BR>> <BR>> <BR>> "Jimmy" =
<</FONT><A=20
href=3D"mailto:j@j.j"><FONT face=3DArial size=3D2>j@j.j</FONT></A><FONT =
face=3DArial=20
size=3D2>> wrote in message <BR>> </FONT><A=20
href=3D"news:OreY4Y10GHA.4108@TK2MSFTNGP04.phx.gbl"><FONT face=3DArial=20
size=3D2>news:OreY4Y10GHA.4108@TK2MSFTNGP04.phx.gbl</FONT></A><FONT =
face=3DArial=20
size=3D2>...<BR>>> ill have a database with 1 table and 3=20
fields:<BR>>><BR>>> ID FIRSTNAME =20
LASTNAME<BR>>><BR>>> (the ID field will be the auto =
incrementing=20
index)<BR>>><BR>>> there might be 10 records in the DB, =
there might=20
be 10,000.<BR>>> i need to open the DB and randomly select a =
record (and=20
then display the <BR>>> name, which i dont have a problem=20
with)<BR>>> how can i randomly select a record? im guessing id =
have to=20
open a <BR>>> recordset and check the count to get the number of =
records,=20
so lets say <BR>>> there were 100 records. i imagine i would have =
to=20
generate a random number <BR>>> between 1 and=20
100....<BR>>><BR>>> anyone have a small=20
example?<BR>>><BR>>> <BR>> <BR>></FONT></BODY></HTML>
------=_NextPart_000_0012_01C6D339.6B9AEDF0--