Andy Levy points out that the TOP operator doesn’t always apply to each element in a UNION:
This system uses
TOP
every now and then trying to limit the number of records it gets back (and the developers always seem to use the arbitrary301
– I’m guessing some degree of cargo cult programming going on). I’d prefer a well-constructedWHERE
clause to limit the result set but beggars can’t be choosers when working with legacy vendor code.What I found odd was that the
Ledger1
table didn’t get a lot of traffic – with theWHERE
clause in use (omitted here for brevity), you’d only get a handful of records, maybe a dozen at most.
Click through to see the rest of the problem, as well as Andy’s solution.