Andy Levy points out that the TOP operator doesn’t always apply to each element in a UNION:
This system uses
TOPevery 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-constructedWHEREclause to limit the result set but beggars can’t be choosers when working with legacy vendor code.What I found odd was that the
Ledger1table didn’t get a lot of traffic – with theWHEREclause 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.