Question: Selecting random records from the db (puzzle of the day)

V

VB Programmer

I am interested to hear your suggestions on this...

I have a table full of survey questions. The questions are individually
classified as priority 1, 2 or 3. (Priority 1 means the question shows up 3
times as much as the others, priority 2 means it shows up 2 times as much as
priority 1.)

I want to fill a temp table with a random selection of these questions.
Example: If I want the temp table to contain 100 random "question" records
then 1/6 of the questions would be priority 1, 1/3 would be priority 2 and
1/2 would be priority 3. Any suggestions/ideas how to do this?

Thanks!
 
P

Prathap

you can try something like this for each priority to push into the temp
table

select top 50 * from survey where priority = 3 order by NEWID()

order by NEWID() --> randomly fetches records for priority 3


Prathap
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top