List of all options and the ones selected - from two tables

  • I have two tables one with a list of options available and another with customers info and their selected options from the first table. with a query, how do I show a list of all the options with the ones the customer has selected?

    I want a user to be able to see a list of options in a check box and select the options they want. I then will save the selected options in the database. If they come back to the page they will see all the options and the ones they previously selected will show checked.

    The list of options in the options table needs to be dynamic. So the checkboxes are created dynamicly.

    example results:

    Returned from the SQL server

    optionID optionName optionDesc ischecked

  • try something like this:

    select O.optionId, O.optionName, O.optionDesc,

    case when S.optionID is null then 'N' else 'Y' end as isChecked

    from Options O left outer join SelectedOptions S

    on O.optionID = S.optionID

    and S.userId = @userid

  • What Antonio has posted is as good of an answer as you'll get without us knowing more about your tables. Since you're a new poster, check this link out for furture reference.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thank you very much.. That's exactly what i was looking for.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply