How to get Random questions everytime user click on random button (in SQL Server)?

Posted by Iluvdotnetfunda under Sql Server on 4/2/2012 | Points: 10 | Views : 1097 | Status : [Member] | Replies : 5
Hello Friends,

I am using below query to get the random records but in some cases the questions been repeating.

SELECT top 1 table.* FROM myTable table WHERE table.active = 1 and table.isExclusive = 0 and table.AutoID < @questionID AND table.AnswerType = 0 order by NEWID()


Thanks&Regards
iluvdotnetfunda




Responses

Posted by: Rajni.Shekhar on: 4/2/2012 [Member] Bronze | Points: 25

Up
0
Down
you can use rand() function also.

Thanks,
Rajni Shekhar

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/2/2012 [Member] Bronze | Points: 25

Up
0
Down
or check below site.....
already discussed in this forum..

http://www.dotnetfunda.com/forums/thread8795-how-to-get-the-random-questions-from-my-datatable-using-sql-server.aspx

Thanks,
Rajni Shekhar

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Iluvdotnetfunda on: 4/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hello Rajni,

The above link is not working.
Can you please send me the "Query"

Thanks
iluvdotnetfunda


Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/2/2012 [Member] Bronze | Points: 25

Up
0
Down
Check it, it is working or not.

SELECT top 1 table.* FROM myTable table WHERE table.active = 1 and table.isExclusive = 0 and table.AutoID < @questionID AND table.AnswerType = 0 order by RAND()



Thanks,
Rajni Shekhar

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Iluvdotnetfunda on: 4/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hello Rajni,

This is also not working, it is giving only one record.
"Only one record is displaying."

Thanks,
iluvdotnetfunda

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response