Click to See Complete Forum and Search --> : Boolean request -> SQL statement
Stevie-O
May 3rd, 2000, 02:02 AM
I need some way of converting a boolean-style request to an SQL statement. Here is an example (don't assume this will have anything to do with cars):
User inputs:
sunroof and four door not red
SQL statement created:
Select * From TblItems Where Description Like '%sunroof%' And Where Description Like '%four door%' And Where Description Not Like '%red%'
I'm well-versed in VB.
However, I do NOT know ASP, nor do I know SQL. This was just dumped in my lap.
Ideas, anyone?
Ianpbaker
May 3rd, 2000, 07:09 PM
This might Help You out.
The SQL statement you wrote looks fine all you need to do is get the information from the user into the statement The following is an example in two sections. The first is the HTML Form and the second the ASP Page.
<FORM action="carpage.asp" method="POST">
<INPUT type="checkBox" value="red" name="notcolor">not red<br>
<INPUT type="checkBox" value="fourdoor" name="door">four doors<BR>
<INPUT type="checkBox" value="sun" name="roof">Sun Roof<br>
<INPUT type=submit>
</FORM>
carpage.asp
Dim ObjCon
Dim objRec
Dim strSQL
Dim strCon
Dim Color
Dim Door
Dim roof
color = Request.Form("red")
Door = Request.Form("door")
roof = Request.Form("roof")
Set ObjCon = CreateObject("ADODB.Connection")
Set ObjRec = CreateObject("ADODB.RecordSet")
strCon = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("your database") ' This connection string is for Access only
strSQL = "SELECT * FROM tblitems"
If color = "red" Then
strsql = strsql & " WHERE Description Not Like '%red%'"
End If
'Use the same If statment for the other requests
objcon.Open strCon
objRec.Open strSql,strCon
Hope this helps Ian
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.