Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How do you randomly select records from a database (ONLY ONCE) until all records have been viewed?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-14 : 22:37:20
Jonny writes "Hi there, i've been searching around on the net and all the answers to my problem that i've found have been a bit confusing. My table is named "mearp" and i need to select a random row from it. All the tutorials/answers that i've found have been ok but most of which just won't work well enough. The main problem being that the random function isn't random enough!
It keeps returning the same result like three times in a row occasionally more or less.


What a I need is a simple script that can pick random records through a Database until all records have been viewed (not showing the same record twice) and then when all have been viewed to start over again.


I'm using access 2000 with win 2000 (default ISS (version 4 i think)) if that helps and i'm coding in Active Server Pages.


If you can help please mail me Toozious@hotmail.com and i'll really love you forever!


Thanks again, Jonny Tooze


(here's my code that i'm using now)


' set rs = conn.execute("Select count(id) from mearp")
' rCount = rs(0)
'
' set rs = conn.execute("select id from mearp")
' cnt = 1
' dim RRs
' redim RRs(rCount)
' do while not rs.eof
' RRs(cnt) = rs(0)
' cnt = cnt + 1
' rs.movenext
' loop
'
' randomize
' currentRR = cLng(rnd*rCount+0.5)
' ID = RRs(currentRR)
'
'
' sql = "select * from mearp where id=" & ID
' set rs = conn.execute(sql)
'
"
   

- Advertisement -