Results 1 to 3 of 3

Thread: Creating dynamic SQL SELECT statement

  1. #1
    Join Date
    Apr 2004

    Creating dynamic SQL SELECT statement

    My web page is layout out with 3 select boxes, the user will select(or not) an option from each box and then click the search button.

    The issue here is, how do I create an SQL SELECT statement which will be based on which options the user selects?
    Full of Kramy goodness

  2. #2
    Join Date
    Jan 2004
    Melbourne, Australia
    You will have to run a few if statements to determine which options the user has selected.
    //' psuedocode. 
    if selectBoxOne.selectedItem = "value"
       //' Statement sequence.
       //' Alternative statement sequence.
    Andrew Buntine.

  3. #3
    Join Date
    Nov 2003
    Also note that it can get a bit hairy depending on what their selections are supposed to do. If they're intended for the WHERE clause, you need to deal with the possibility that they won't select anything, in which case you need to be sure not to leave a naked WHERE sitting around. An easy way to deal with it (if all the options will use AND logic) is to end the static portion of the query with "WHERE 1 = 1" and then you can append as many or as few options on the end in the form " AND whatever_option = 'whatever_value'" as you want without needing to worry about dealing with no options selected or handling the first selected option specially.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center