On 25 Jul 2005 11:00:01 -0700,
wa********@yaho o.com wrote:
Is Set RowCount @RowCount
More efficient than simply using TOP?
Thanks for any input.
Hi wackyphill,
Depends. They have different characteristics .
SET ROWCOUNT:
- takes a variable as well as a constant,
- affects ALL future queries, until another SET ROWCOUNT is executed,
- affects only the end result of the complete query.
TOP:
- takes only a constant,
- affects only the current query,
- may be used to limit the number of rows in a subquery.
If you want to limit output from all your queries to twenty rows for
testing and debugging purposes, SET ROWCOUNT is easily the best: just
issue the command once, then run all your queries without the need to
change. If you want to limit the output to a number determined at
runtime, SET ROWCOUNT wins as well - pop the value in a variable, then
run SET ROWCOUNT @NewLimit.
On the other hand, if each query needs another limit, TOP is more
efficient since you'd otherwise have to run a SET ROWCOUNT between all
your queries. And if you're trying to find the salesmen that are NOT
amongst the 10 best sellers, SET ROWCOUNT can't be used at all, whereas
TOP can.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)