Results 1 to 2 of 2

Thread: Boolean request -> SQL statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Location
    Hell
    Posts
    89

    Exclamation

    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?
    - Steve

    Real programmers use COPY CON PROGRAM.EXE

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Smile

    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.

    Code:
    <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

    Code:
    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



    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

Posting Permissions

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



Click Here to Expand Forum to Full Width