How to randomly pick exam questions from database(sql server)

  • 13 years ago

    i'm implementing an examination system. Did anyone know how to randomly pick exam questions from the database. i'm using sql server 2000 and vb.net

  • 13 years ago

    You can select a random row using following stored procedure:


    Declare @LastId int, @RndId int, @Lower int, @Upper int

    Select @LastId = Max(QuestionId) From dbo.Questions

    Gen_Rnd:
    SET @Lower = 1
    SET @Upper = @LastId
    SELECT @RndId = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

    If Exists(Select * From dbo.Questions Where (QuestionId = @RndId))
    Select * From dbo.Questions Where (QuestionId = @RndId)
    Else
    Goto Gen_Rnd
  • 13 years ago

    ok. but using this code i hv to pass question id then only able to retrieve..but for my system when i click the start exam button , the first question should randomly pick from the database and appear(the user no need to gv the question id).....and another thing is there any possibilities to code it in vb.net itself....help meee

  • 13 years ago

    I'm not sure if this will assist you in your situation but I have used

    SELECT TOP 10 * FROM tblExamQuestions ORDER BY newID()

    This SELECTs 10 rows randomly from the table...

    Thanks

    Musa

  • 13 years ago

    ya it;s help me alot thank you....

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond