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

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.