views:

73

answers:

3

I try to create standardized SQL scripts for use in my SSRS reports. If I wish to have a statement such as:

Select * from mytable

and use a SQL Variable (SSRS parameter) in the where clause, is there any speed advantage to using this:

Where field = @MyField

VS.

Where field IN (@MyField)

I know the second option supports both multiple selections and single selections while the first supports only single.

Are there any performance hits if I write all my queries with the IN statement for uniformity?

+3  A: 

There is no performance hit. The optimizer converts the IN to a series of = operations ORed together.

As a side note, I hope you're not really using SELECT * in your actual queries.

Joe Stefanelli
No of course not. I was just saving time rather than typing Field1, field2 etc.
DavidStein
@joe: What's wrong with `select *` ?
jpartogi
A: 

For one argument optimizer will change that IN into =, in real execution statement.

As both of this arguments are Sargeble (Joe Stefanelli thanks for attention); the difference in performance may by found where you have sequence value in in clause, for example IN (1,2,3,4,5,6) is slower that between 1 and 6, because for the IN the index has to be read for each value in this case 6 time for between only once.

Vash
This is incorrect. IN is sargable, NOT IN is not sargable.
Joe Stefanelli
After some googling i must admit that You have right, on some dev blog it was written that this is also nonsargable. Thanks.
Vash
@Vash, I noticed you supplied a similar answer to this earlier question. You might want to amend that answer as well.http://stackoverflow.com/questions/3353084/sql-efficiency-vs-in-vs-like-vs-matches/3353223#3353223
Joe Stefanelli
A: 

the performance does get slow if you have a large no of item in your IN clause