By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

random selection

P: 3
am having a problem of selecting 40 rows at random from a table every single time this is my code:

Expand|Select|Wrap|Line Numbers
  1. Set oRs = oDatabase.Execute("SELECT Top 40 * FROM Questions ORDER BY Rnd(QID)", , adOpenForwardOnly Or adLockReadOnly) 
and i also try this code not working for me: Here is the syntax (x = table, ID = field)


Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 x.ID
  2. FROM x
  3. ORDER BY Rnd([id])*[id]*Now();
Pls Help me.....
Jun 22 '12 #1
Share this Question
Share on Google+
5 Replies


100+
P: 759
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP n X.*
  2. FROM X
  3. ORDER BY Rnd([ID])*[ID]*Now();
where "n" is the number of records ( =1 or =40 )
Jun 23 '12 #2

P: 3
Thanx Mihail for you concern i tried this code:

Expand|Select|Wrap|Line Numbers
  1. Randomize
  2.   Set oRs = oDatabase.Execute("select top 40 Questions.* from Questions order by rnd([QID])*[QID]*Now()")
where Questions =table

My problem is the same set of question row is been selected at random at every run time
Jun 25 '12 #3

Rabbit
Expert Mod 10K+
P: 12,316
Please use code tags when posting code.

Your parentheses is in the wrong place.
Expand|Select|Wrap|Line Numbers
  1. select top 40 Questions.* 
  2. from Questions 
  3. order by rnd([QID]*[QID]*Now())
Jun 25 '12 #4

P: 3
thanx Rabbit but the code is not randomizing
different row at every run time....
Expand|Select|Wrap|Line Numbers
  1. Randomize
  2. Set oRs = oDatabase.Execute
  3. ("select top 40 Questions.* from Questions
  4.  order by Rnd([QID])*[QID]*Now()")
and i also try this:
Expand|Select|Wrap|Line Numbers
  1. Randomize
  2.   Set oRs = oDatabase.Execute
  3. ("select top 40 Questions.* from Questions
  4.  order by Rnd([QID]*[QID]*Now())")
Jun 27 '12 #5

Rabbit
Expert Mod 10K+
P: 12,316
Please use code tags when posting code. This is your second warning.

First of all, your code can't possibly run. Execute is for action queries and what you have is not an action query. So when you say that it's not randomizing, I have no idea how you can even say that if the code won't even run.
Jun 27 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.