Click to See Complete Forum and Search --> : 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?
buntine
05-10-2004, 03:18 AM
You will have to run a few if statements to determine which options the user has selected.
//' psuedocode.
if selectBoxOne.selectedItem = "value"
//' Statement sequence.
else
//' Alternative statement sequence.
Regards,
Andrew Buntine.
CardboardHammer
05-10-2004, 11:17 AM
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.