469,607 Members | 1,982 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

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

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!
Nov 18 '05 #1
2 1244
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

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 18 '05 #2
http://www.sqlteam.com/item.asp?ItemID=8747 - if you're using Windows 2000
or higher
http://www.sqlteam.com/item.asp?ItemID=896 - otherwise

Alan

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jason | last post: by
12 posts views Thread by Joseph Shraibman | last post: by
3 posts views Thread by John Fairhurst | last post: by
2 posts views Thread by megahurtz | last post: by
4 posts views Thread by honey777 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.