How do I.....

Results 1 to 2 of 2

Thread: How do I.....

  1. #1
    Joshua Mann Guest

    Default How do I.....

    I have a SQL database, I need to pull all the entries into a recordset that fall in between user specified dates. Then I need to pick a random entry from the recordset and display it. How can I do this? Please help if you can...Thank You.

  2. #2
    Joe Kimbler Guest

    Default RE: How do I.....

    Try...<BR><BR>DIM objConnect<BR>DIM objRecords<BR>DIM sqlQuery<BR><BR>Set objConnect = Server.CreateObject("ADODB.Connection")<BR>Set objRecords = server.CreateObject("ADODB.Recordset")<BR>objConne ct.Open "MyDSN", "MyUserID", "MyPassword"<BR><BR>sqlQuery = "SELECT * FROM table WHERE datefield &#062;= #"<BR>sqlQuery = sqlQuery & startdate & "# AND datefield &#060;= #"<BR>sqlQuery = sqlQuery & enddate & "#"<BR><BR>objRecords.Open sqlQuery, objConnect<BR><BR>If Not objRecords.EOF Then<BR> &#039-- There are records<BR> Randomize<BR> &#039-- The next statement will create a random number between 1<BR> &#039-- and the number of records in the recordset<BR> MyValue = Int((objRecords.RecordCount * Rnd) + 1)<BR> objRecords.Move MyValue<BR> Response.Write MyValue & " = " & objRecords.Fields("datefields")<BR>Else<BR> &#039-- There are no records<BR> Response.Write "No records returned..."<BR>End If

Posting Permissions

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