Home All Groups Group Topic Archive Search About
Author
16 Sep 2005 9:50 PM
David Chase
I have a need for a criteria to be = 32 or 33 and wondered if BETWEEN 32 AND
33 would be faster than IN(32,33).  This is an indexed field.  Thanks.

David

Author
16 Sep 2005 9:46 PM
Robbe Morris [C# MVP]
When you timed this yourself, what was the result?
What did the query analyzer explain plans say?

I'd bet the optimizer would alter your code to
whatever it thinks is fastest (yes, sql server optimizer
does do this).  That said, I'd bet you wouldn't
see a different in either approach.

I'd use the IN clause because it is a direct
comparison versus a math comparison.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
EggHeadCafe's RSS Search Engine
http://www.eggheadcafe.com/articles/multisearch/default.aspx




Show quote
"David Chase" <dlch***@lifetimeinc.com> wrote in message
news:e0%23qscwuFHA.2504@tk2msftngp13.phx.gbl...
>I have a need for a criteria to be = 32 or 33 and wondered if BETWEEN 32
>AND 33 would be faster than IN(32,33).  This is an indexed field.  Thanks.
>
> David
>
Author
16 Sep 2005 9:52 PM
David Portas
I know it would have been faster to try it than to ask that question. The
best answer to performance questions is to try it out for yourself. We don't
have access to your schema, your data and your hardware.

--
David Portas
SQL Server MVP
--
Author
17 Sep 2005 6:06 AM
R.D
Hi
as others suggested, you can test with execution paln, time etc.
But include OR also, that is the best.
IN may have additional ovehead.
Regards
R.D


Show quote
"David Portas" wrote:

> I know it would have been faster to try it than to ask that question. The
> best answer to performance questions is to try it out for yourself. We don't
> have access to your schema, your data and your hardware.
>
> --
> David Portas
> SQL Server MVP
> --
>
>
>
Author
17 Sep 2005 8:37 PM
Hugo Kornelis
On Fri, 16 Sep 2005 23:06:02 -0700, R.D wrote:

>Hi
>as others suggested, you can test with execution paln, time etc.
>But include OR also, that is the best.
>IN may have additional ovehead.

Hi R.D.,

IN(value, value, ...) is exactly equal to a set of OR conditions. Just
check out the execution plan of a query that uses an IN condition.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

AddThis Social Bookmark Button