In what sequence do the operators work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jaswanth Singh
    New Member
    • Jan 2011
    • 1

    In what sequence do the operators work?

    Dear Contributors,

    I am new to VBA and SQL and I rquest your help.

    Please explain me how the operators work?
    In what sequence?
    How to put perantheses for the opearation sequence being "OR" first and "AND" next?

    here is the code:

    einSqlStmt = einSqlStmt1 & _
    " IN ( " & vorfilterString & ", NOT " & vorfilterString 1 & " AND NOT " & vorfilterString 2 & " ) "




    Thanks in advance for any help.

    Regards,
    Jaswanth
  • pod
    Contributor
    • Sep 2007
    • 298

    #2
    that is a loaded question ...

    but here goes a few basic rules:


    AND: all [statement]s must be true
    Ex1: TRUE = [TRUE] AND [TRUE]
    Ex2: FALSE= [TRUE] AND [FALSE]

    OR: at least one [statement] must be true
    Ex3: TRUE = [TRUE] OR [TRUE] OR [TRUE]
    Ex4: TRUE = [FALSE] OR [TRUE] OR [FALSE]

    What is in a parenthesis is processed first and separately
    Ex5: TRUE = [TRUE] OR ( [TRUE] AND [FALSE] )
    Ex6: FALSE= ( [TRUE] OR [TRUE] ) AND [FALSE]


    If you have inner level parenthesis, the deepest ones have precedence :
    Ex7: TRUE = [FALSE] OR ( [TRUE] AND ( [TRUE] OR [FALSE] ) )


    hope that helps ...
    Last edited by pod; Jan 24 '11, 02:55 PM. Reason: improving my answer

    Comment

    • mshmyob
      Recognized Expert Contributor
      • Jan 2008
      • 903

      #3
      Your SQL string has been built wrong.

      The & symbols is just conconcates your string.

      einSqlStmt = einSqlStmt1 & " IN ('" & vorfilterString & "', NOT '" & vorfilterString 1 & "' AND NOT '" & vorfilterString 2 & "');"

      Notice the single quote as in '" or "'

      I didn't look at your Logical operators to see if they are correct just your sysntax of the SQL statement.

      cheers,

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        Jaswanth,

        What are you trying to accomplish?

        Are you trying to build a complex boolean statement, or a series of options in an SQL IN expression? Or, perhaps a combination of both?

        Nevertheless, if you are unsure of operator precedence, then use parentheses. Do not even waste time looking it up, as if you do not know it, then the next programmer after you will probably not understand what you wrote, anyway.

        Also, if you use parentheses, then there is no ambiguity in the expression at all - simpy put, using parentheses removes the chance of an inadvertent mistake - the code will mean exactly what you want it to.

        That said, if you can clarify exactly what you are trying to accomplish, maybe we can help you out with more than vague statements.

        Luck!
        Oralloy

        Comment

        Working...