Results 1 to 5 of 5

Thread: SQL Statement - what the

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    SQL Statement - what the

    Hey All,

    Any idea what's wrong?
    Half asleep i know i've missed something.

    VB Code:
    1. strSQL = "Select * FROM tbl_Part WHERE [Model] LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    2.         & "OR PartNumber LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    3.         & "OR Description LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    4.         & "AND Country ='Australia';"

    This returns all records regardless of the Country??

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Put all the ORs in brackets:

    Code:
    strSQL = "Select * FROM tbl_Part WHERE ( [Model] LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    		& "OR PartNumber LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    		& "OR Description LIKE '%" & Replace(varSearch, "'", "''") & "%' " _
    		& ") AND Country ='Australia';"

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Yes, that is correct. You have OR statement in there....you need to put brackets around them, ie:
    Code:
    SELECT * 
    FROM tblUsers
    WHERE (Username = 'Moose' OR Username = 'Badger') AND Banned = 0
    Does that help?

    Woka

  4. #4

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Beautiful thanks guys.

    Too many things going on shoulda known that.

    b

  5. #5
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    RESOLVED ?
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

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