Want a "random sample" from a query

G

Guest

I am trying to run a query to be used in generating a survey to customers. I want my query to return a random sample of records, (e.g., 5%) of the selected records. In other words, I want to survey only a small, random sample of my customers

Can anyone help me
 
G

Gary Walter

Jim Z said:
I am trying to run a query to be used in generating a survey to customers. I want
my query to return a random sample of records, (e.g., 5%) of the selected records.
In other words, I want to survey only a small, random sample of my customers.Hi Jim,

A typical method is to sort your records
randomly, then return top 5% of that sort:

- if you have a non-negative autonumber PK
(say "CustomerID" in table "Customer")

SELECT TOP 5 PERCENT Customers.*
FROM Customers
ORDER BY Rnd([CustomerID]);


- or if you have a text field
(say "CompanyName" in table "Customer")

SELECT TOP 5 PERCENT Customers.*
FROM Customers
ORDER BY Rnd(1 + Len([CompanyName] & ""));

Rnd() needs a non-negative, non-zero, non-null argument.

Please respond back if something is not clear
or I have misunderstood.

Good luck,

Gary Walter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top