CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: SQL query

  1. #1
    Join Date
    Nov 2002
    Posts
    13

    SQL query

    Hi,

    I want to know if it's possible to use together bot AND and OR operators in a SQL statement, and if it is, how?
    It's for an advanced search, and some fields work has a OR, and the others work has a AND.

    Ex: Field1, Field2, Field3, Field4

    Field1=text AND Field2=text AND (Field3=text OR Field4=text),

    is this possible???

  2. #2
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249
    Yes. Use parentheses to set your precedence order ... Just as you did in your example

  3. #3
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309
    If you do without the parenthsis like this

    Field1=text AND Field2=text AND Field3=text OR Field4=text

    it would be ran as though you did this

    (Field1=text AND Field2=text AND Field3=text) OR Field4=text


    so it is better to qualify your sections to ensure the right outcome.

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

Featured