I have a sql statement (inherited) that has the following WHERE clause:
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), '!#') <> '!#')
AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
I'm trying to figure out the order of operations when things are not nicely bracketed.
How are AND and OR statements ordered in the above example?
Is there an easy rule so that I can put brackets around things to make it more readable?
I'm looking for something like "BODMAS" when it comes to the mathematical order of operations, for SQL WHERE clause operators.
Thanks