Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

rand() in access 2000 ?

Posted on 2003-11-03
2
1,169 Views
Last Modified: 2006-11-17
hi!

i have written a program using mysql.
in a query i´m using order by rand().

now i have to switch to access. but it seems that
there is no rand() function.

how can i handle this?
0
Comment
Question by:StoreMaster
2 Comments
 
LVL 23

Accepted Solution

by:
heer2351 earned 50 total points
ID: 9669772
The msaccess equivalent for rand is rnd
0
 
LVL 77

Expert Comment

by:peter57r
ID: 9669830
There is a rnd() function in Access; but you can't use it in the way you are trying to.

To generate a random field in a query you need to force Access to think that the random number is dependent on a field in the record or else the rnd() value is just calculated once at the start of the query and that value used on all records.

So you can include rnd([anyfield]) and this produces a different result for each record.

You can sort on this value in a query.  Unfortunately, by the time the data is displayed, the random function has triggered again and the numbers have changed so that they appear not to be in order.   If you want to retain the random number sequence you must first write the value to a new field in an update or make-table query and then use another query to present the sorted data.

Pete


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question