Random record SQL

Results 1 to 3 of 3

Thread: Random record SQL

  1. #1
    Join Date
    Dec 1969
    Posts
    538

    Default Random record SQL

    What is the SQL query to reterive a random record with a where clause in it.<BR>THANKS&#060;

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Random record SQL

    There&#039s not an inherent SQL command that will choose a random record from a recordset. However, I have written a short article on how to grab a random record from a recordset.<BR><BR>See:<BR><BR>Choosing a Random Record from a Recordset <BR>http://www.4guysfromrolla.com/webtech/072799-1.shtml<BR><BR>Please let me know if you have any further questions on this issue! :)

  3. #3
    Join Date
    Dec 1969
    Posts
    538

    Default SCOTT M!!!!!!!

    I looked at the pick a random record code and I&#039m trying to modify it please help.<BR><BR>&#060;% Option Explicit %&#062;<BR><BR>[an error occurred while processing this directive]<BR><BR>&#060;%<BR>Dim objConn<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .ConnectionString = "DSN=;UID=;PWD=;"<BR>objConn.Open "dsn=;uid=;PWD=;"<BR> <BR>Dim objRS<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR>objRS.Op en "SELECT * FROM TABLE WHERE PIC&#060;&#062;&#039unavailable.gif&#039", "dsn=;uid=;PWD=;"<BR><BR> Dim rndMax<BR> rndMax = CInt(objRS.RecordCount)<BR> objRS.MoveFirst<BR> <BR> Do WHile Not objRS.EOF<BR> Response.Write objRS("PIC") & "<BR>"<BR> objRS.MoveNext<BR> LOOP<BR> <BR> objRS.MoveFirst<BR> <BR> Dim rndNumber<BR> Randomize Timer<BR> rndNumber = Int(RND * rndMax)<BR> <BR> objRS.Move rndNumber<BR><BR> Response.Write objRS("PIC")<BR><BR><BR> objRS.Close<BR> Set objRS = Nothing<BR> <BR> objConn.Close<BR> Set objConn = Nothing<BR>%&#062;&#060;/XMP&#062;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •