• david.wright-948385 (2/12/2014)


    Always add brackets when mixing operators. Even if you know the rules, brackets make a calculation less prone to misunderstanding.

    Until you have several layers of brackets, at which point pairing them up can become as difficult as parsing the text. This can be alleviated by formatting, e.g:

    WHERE

    (

    (a = b)

    OR

    (b = c)

    )

    AND

    (

    (c = d)

    OR

    (

    (d = e)

    AND

    (e = f)

    )

    )

    as opposed to

    WHERE ((a = b) OR (b

    = c)) AND ((c = d) OR (

    (d = e) AND (e = f)))

    The latter, of course, being the type of code outputted by Microsoft's query designers on a regular basis...