Results 1 to 3 of 3

Thread: Access 2000 RND with Microsoft.Jet.OLEDB.4.0

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Question Access 2000 RND with Microsoft.Jet.OLEDB.4.0

    I have a M$ Access 2K DB which has a single table and a query saved in it.

    The Query Starts SELECT * FROM MyTable but goes on to add a "new" field using RND() seeded with the Now() and [id].

    The same SQL is used directly in my ASP page.

    If I access the Query or create a connection to the table using the SQL the result is the same. If I connect again and do the same the result is still the same.

    It should be different as I am ordering by the RND col.

    I'm useing Microsoft.Jet.OLEDB.4.0 (if it makes any difference) and I want to know if anyone knows a way to slap a RANDOMIZE instruction on the DB to "refresh" the RND order of rows.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Access 2000 RND with Microsoft.Jet.OLEDB.4.0

    hi

    try something like this:
    Code:
    SELECT Table1.*, Random([id]) AS OrderByMe
    FROM Table1
    ORDER BY Random([id]);
    I had to make a function Random because I stupidly made a project called rnd and it didn't like that confused Access.

    Change Random to Rnd and make sure it uses the unique ID as this forces the call each time rather than calcing a value once and reusing... which is what yours is probably doing and what my first attempt did

    Good luck

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Unhappy Re: Access 2000 RND with Microsoft.Jet.OLEDB.4.0

    I've gotten pritty excessive in my search for a random number

    I use the following:

    rnd([id]) rnd(second(now()) and other nested requests

    I'll explain now that there are 3 connection coditions that are used the random is just the most complex...

    I connect useing a single sub (below)

    the Random is called when spec = "showad" and at the moment I've taken to randomly selecting one of 9 possible randomising methods the result is that each user now has a total of 9 results and no way of knowing which they will get... it's not quite random... but it is different for each user.

    VB Code:
    1. sub openconn
    2.  
    3.     DB_CONNECTIONSTRING = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    4.         & "Data Source=" & Server.Mappath("./../../private/refads.mdb") & ";"
    5.  
    6.     Set objRecordset = Server.CreateObject("ADODB.Recordset")
    7.     connstr = "refads"
    8.     if spec = "showref" then connstr = "SELECT * FROM refref where [url] = '" & URL & "';"
    9.     if spec = "showad" then
    10.         dim harry, freddy, jonny
    11.             harry = rnd(Second(Now())*100)
    12.  
    13.             freddy = round(rnd(20)+1)
    14.  
    15.         select case freddy
    16.             case 1
    17.                 Jonny = "max(Rnd(-(Second(rnd([id]*100))*" & harry & "*rnd([id]*100))))"
    18.             case 2
    19.                 Jonny = "max(Rnd(-(Hour(rnd([id]*100))*[Date]*rnd([id]*100))))"
    20.             case 3
    21.                 Jonny = "max(Rnd((Second(rnd([id]*100))*rnd([Date]))))"
    22.             case 4
    23.                 Jonny = "max(Rnd(-(Second(rnd([id]*-1000))*" & harry & "*rnd([id]*100))))"
    24.             case 5
    25.                 Jonny = "max(Rnd((Second(rnd([id]*-500))*" & harry & "*rnd([id]*100))-rnd(now())))"
    26.             case 6
    27.                 Jonny = "max(Rnd(-(Second(rnd([id]*100))-rnd(now()+[id])*" & harry & "*rnd([id]*100))))"
    28.             case 7
    29.                 Jonny = "max(rnd([Date]))"
    30.             case 8
    31.                 Jonny = "max(rnd([Date])*rnd(now()+[id]))"
    32.             case else
    33.                 Jonny = "max(iif(round(rnd(3)))>1, " & _
    34.                 "Rnd(-(Second(rnd([id]*100))-" & harry & ")), " & _
    35.                 "iif(rnd(id*2)>id),rnd(rnd([id])+rnd(1)+rnd(2)-rnd(3)+rnd(4)), 5+rnd([Date])+rnd(2)-rnd(3)+rnd(4)+rnd(1)+rnd(2)-rnd(3)+rnd(4)+rnd(1)+rnd(2)-rnd(3)+rnd(4))"
    36.         end select
    37.  
    38.  
    39.  
    40.         connstr = "SELECT TOP 3 * FROM (SELECT TOP 20 * FROM (" & _
    41.         "SELECT Max(refads.Date) AS MaxOfDate, refads.URL, refads.CallMe, refads.title, " & _
    42.         Jonny & " AS bob " & _
    43.         "FROM refads " & _
    44.         "GROUP BY refads.URL, refads.CallMe, refads.title " & _
    45.         "HAVING (((Month(Max([refads].[Date])))>=Month(Now())-1)) " & _    
    46.         "ORDER BY " & Jonny & " DESC  " & _
    47.         ") as RNdADS where [url] <> '" & URL & "' ORDER BY bob) as sumit ORDER BY bob DESC;"
    48.         if code = "999" then connstr = "refads"
    49.     end if
    50.     objRecordset.Source           = connstr
    51.     objRecordset.ActiveConnection = DB_CONNECTIONSTRING
    52.     objRecordset.CursorType       = adOpenKeyset
    53.     objRecordset.LockType         = adLockOptimistic
    54.     objRecordset.Open
    55.  
    56. end sub
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

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



Click Here to Expand Forum to Full Width