Getting Started with ASP.NET MVC - Part 5: How to do programming with razor syntax
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Loading

Ask in the public forum

Ask your questions in a public forum

My Blog Posts

  • Want Querry

    Hi friends i am basically from .net developer, i have one problem that i have to prepare a database that contains columns questionNo,Question,Option1,Option2,Option3 ,Option4,ActualAnswer. My problem is to whenever my page is refreshed Options1,Options2,Options3,Options4 should be rearranged every time.

    Ravikumar
    1689 · 0% · 5

1  Replies  

Subscribe to Notifications
  • please post your query to get data, in general to get the data in order use order by in your query.

    If you want your four option in single column in order by QuestionId and Option then try this query

    SELECT  Qno,Options,OptionValues
    FROM
    (
    SELECT questionNo AS QNo,Option1 AS [1],Option2 AS [2],Option3 AS [3],Option4 AS [4]
    FROM Quiz)P
    UNPIVOT
    (OptionValues FOR Options IN ([1], [2], [3], [4])
    ) AS Unpvt
    order BY Qno,Options
    

    OR

    SELECT * FROM (
    SELECT questionNo,1 AS OptNo,Option1 AS Options FROM Quiz
    UNION ALL 
    SELECT questionNo,2 AS OptNo,Option2 FROM Quiz
    UNION ALL 
    SELECT questionNo,3 AS OptNo,Option3 FROM Quiz
    UNION ALL 
    SELECT questionNo,4 AS OptNo,Option4 FROM Quiz
    )AS tmp
    ORDER BY questionNo,OptNo
    
    Mitesh Modi
    87 · 2% · 560

Your Reply


Sign Up or Login to post an answer.

Managed Windows Shared Hosting by OrcsWeb

Copyright © Beyondrelational.com