Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basing sql statement on checkbox values not equal to ""

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
I have multiple checkboxes (plus other misc text boxes) in a form. Each checkbox has a unique name and value, with the value corresponding to an field in a table (for use in compiling page 2)

At the bottom of the form I have a continue (submit) button that opens a new page. When the "Continue" button is checked, I'll have vbscript code in an include statement which will build a dynamic list of checkboxes.

What I'm trying to figure out is how to build the sql statement for my include file, that says: If a checkbox has been checked, take the value of that checkbox (which corresponds to a certain field in the table i need to query) and pull all records that have that value in the field and build a table on page 2 with checkboxes for each of them, then so on and so forth for each checkbox value from page 1 not = "".

I hope someone knows what I'm trying to say, and can help me. I'm learning asp and vbscript as I go and need some assistance. I understand that if a checkbox is not checked that the value isn't passed, but I don't understand how to work with the information that is and have never worked with arrays and don't really understand them. Thanks everyone!!!!! [sadeyes]
 
Start building your SQL statement as normal.

Code:
strSQL = "SELECT val1, val2, val3 FROM myTable WHERE "

if len(request.form("ckboxvar1")) then
  strSQL = strSQL & "val1 = '" & request.form("ckboxvar1") & "'"
end if

Essentially, this will check to see if you have a value in your checkbox and, if so, will then allow you to add to the conditional part of your SQL statement. HTH

--------------------------------------------------------------------------------------------------------------------------
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
--Douglas Adams
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top