Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Posts
    3

    Exclamation Unanswered: Multiple AND statements one table

    How can I use more than two AND clauses in a Parameterized SQL query?
    Example:

    SELECT NAME, ADDY, PHONE, DOB
    FROM CONTACTS
    WHERE (NAME LIKE ?) AND (PHONE LIKE ?) AND (Format(DOB, 'yyyy/m/d') LIKE ?)
    ORDER BY NAME

    When I use this and enter a valid DOB, I get no results.

  2. #2
    Join Date
    Jun 2005
    Posts
    61

    Lightbulb HI Mrakes

    i used this Sql Statment
    M0 is a field Name ( Make In My Table )
    S0 Is Field Data

    SELECT CYear, " & M0 & ", Sum(Qty) As Qty From CarSales Where
    " & M0 & "= '" & S0 & "' or CarSales." & M0 & "= '" & S1 & "' and
    CYear >= " & fy1 & " And CYear <= " & ty1 & " GROUP BY " & M0 & ", CYear ;", db, adOpenDynamic, adLockOptimistic


    i Hope This Will Help U
    Sami
    Sami Al Damiri ...

  3. #3
    Join Date
    Mar 2006
    Posts
    3
    I have an MS Access DB. I am writing an app in VB.net that queries the DB. The app contains three input fields. and outputs the results into a dataset. I want the user to be able to enter any value (or no value) into any field and get results matching the criteria entered. If the user does not enter anything into a field, I am passing % on as wildcard for that field and appending % to any value entered into a field. In my SQL Query Builder, this works great if I only state WHERE [condition] AND [condition]. I can use any two of the three criteria and get results. However, if I try WHERE [condition] AND [condition] AND [condition], I do not get any results. Your example may be a good idea, but unfortunately, I do this very rarely and do not quite understand you.

  4. #4
    Join Date
    Mar 2006
    Posts
    3
    I think I know what's going on. Some of my entries contain an empty field. One entry may not contain a Phone #, while other entries may not contain a DOB. If I am selecting a person who contains an empty field, I do not get any results. How can I get around this?

Posting Permissions

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