Results 1 to 6 of 6

Thread: sql problem

  1. #1
    Join Date
    Jun 2002
    Posts
    173

    Unanswered: sql problem

    I'm using the following sql statement for a record set in a web page:

    SELECT *
    FROM tbl3
    WHERE col11 ='colcheck' AND col2 LIKE '%colname%' or col1 LIKE '%colname%' or col3 LIKE '%colname%' or col4 LIKE '%colname%' or col5 LIKE '%colname%' or col6 LIKE '%colname%' or col7 LIKE '%colname%' or col8 LIKE '%colname%' or col10 LIKE '%colname%'
    ORDER BY col2

    It receives a value of 0 or 1 for the colcheck variable and can receive any input from the user for colname. It's just a simple search for contact info. The colcheck is whether or not the client is active. 1=active, 0=nonactive. Then the second colname entry allows the user to enter one search string that will search all the fields in the table. But when I execute the searches it doesn't seem to lock it down by the active/nonactive status. It seems to do the search on or and/or the other search variable. I thought the above code would lock it down to find a definite combinate of the two variables not just either/or.

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    What does lock it down mean?

    Also "%anything%' is bad...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Nov 2003
    Posts
    54
    I believe by 'lock down' he means it is not selecting based on the colcheck field. You will need to group your set of OR statements together using Paren () - the way you have it written the OR overrdes the AND.

  4. #4
    Join Date
    Jun 2002
    Posts
    173
    ok thanks. i tried the () and it works now. does that go for any additional parameters I need? just enclose them in ()?

  5. #5
    Join Date
    Jun 2002
    Posts
    173
    Originally posted by Brett Kaiser
    What does lock it down mean?

    Also "%anything%' is bad...


    Brett,
    I'm using the %anything% so that any field can be searched on in the table by only entering a search string in one place. Are there better ways around this other than creating a record set based off each searched field individually?

  6. #6
    Join Date
    Nov 2003
    Posts
    54
    If you are going to be adding them to your chain of OR statements, yes, enclose in (). Any thing enclosed will be considered part of the 2nd element of the AND statement, and executed at the same time. Think back to Algebra and you should get all the logic you need.

Posting Permissions

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