In my opinion, your where
clauses take up too much vertical space and can be made more maintainable. Compare what you have with this:
where b.name = N'python' and b.class = 3 -- 1 is gold, 2: silver, 3: bronze and u.Reputation >= 1000 and ( lower(u.Location) like '%nyc%' or upper(Location) like '%NY, NY%' or lower(Location) like '%staten%' or lower(Location) like '%bronx%' or lower(Location) like '%queens%' or lower(Location) like '%new york, ny%' or lower(Location) like '%manhattan%' or lower(Location) like '%brooklyn%' )
Suppose you're working on this query and you want to remove the Reputation condition to see what happens. In your version, you'd have to comment out two lines. In mine you'd only have to comment out one, although this doesn't work with your large and
condition, nor does it work with your first condition (the only one that doesn't start with and
). Note that it's a matter of convention whether your conditions put the and
at the beginning or the end of the line.
I've seen some people write their where
clauses like this:
where 1=1 and b.name = N'python' ...
In this way, it's easy to comment any single-line conditions: you just put a --
at the front. This is a step too far for me. I just put the conditions I'm most sure of at the top.