Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

No Math In Where Clause

From Wiki

Jump to: navigation, search

Don’t use arithmetic operators on a column in the where clause

You will get an index scan instead of a seek. It is better to move the operation away from the column.

  1. SELECT * FROM Orders WHERE OrderID*3 = 33000
  2. SELECT * FROM Orders WHERE OrderID = 33000/3

Take a look at the execution plan of these two queries


Image:QueryPlan.jpg


Contributed By: --SQLDenis 15:26, 31 May 2008 (GMT)

Part of SQL Server Programming Hacks - 100+ List

Section Query Optimization

112 Rating: 2.4/5 (8 votes cast)