Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Performance question

Author  Topic 

Elijah
Starting Member

3 Posts

Posted - 2009-12-20 : 17:32:06
Im just getting back into SQL after about 3 years.
Im seeing alot of bad coding on a project im on that is in Coldfusion with more queries being ran on a single page than I have ever seen before. Litterally some pages are hitting 800+db calls.

So staring with a basic query for performance purposes which would be less taxing on the server.
i.e.
Select someField
From tblX
Where id=1 or id=3 or id=10 or id=11 or id=13 or id=19


or
Select someField
From tblX
Where id in (1,3,10,11,13,19)


Thank you for looking.

Elijah
Starting Member

3 Posts

Posted - 2009-12-20 : 17:33:08
Oh, if you could also explain why I would appreciate it also.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-20 : 18:12:56
They are equivalent because the query parser converts IN to ORs anyway.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

Elijah
Starting Member

3 Posts

Posted - 2009-12-20 : 18:46:45
Well, if "They are equivalent because the query parser converts IN to ORs anyway."
Then it would be more efficient to just write the SQL with the or's in order to no tax the server to do the conversion on the DB server. Am I correct?

Thank you for the information.
Elijah
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-20 : 19:20:25
No, the performance is still the same.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -