title: Order of operation for AND and OR in SQL Server queries
body: <p>I have a sql statement (inherited) that has the following WHERE clause:</p>
  
  <pre><code>WHERE
            (Users_1.SecurityLevel IN ('Accounts', 'General manager'))
        AND (PurchaseOrders.Approval = 1)
        AND (PurchaseOrders.QuotedAmount = 0)
        AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
        OR
        (Users_1.SecurityLevel IN ('Accounts', 'General manager'))
        AND (PurchaseOrders.QuotedAmount = 0)
        AND (ServiceRequests.POC = 1)
        AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
        OR  
          (ISNULL(ISNULL(PurchaseOrders.InvoiceNumber, ServiceRequests.InvoiceNumber), '!#') &lt;&gt; '!#')
        AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
  </code></pre>
  
  <p>I'm trying to figure out the order of operations when things are not nicely bracketed.</p>
  
  <p>How are AND and OR statements ordered in the above example?</p>
  
  <p>Is there an easy rule so that I can put brackets around things to make it more readable?</p>
  
  <p>I'm looking for something like "BODMAS" when it comes to the mathematical order of operations, for SQL WHERE clause operators.</p>
  
  <p>Thanks</p>