Ian Jose's WebLog

This weblog is intended to help T-SQL developers get the best performing query plans from SQL Server. Some of the posts describe simple mistakes that can be easily avoided. Other posts describe complex solutions to limitations in SQL Server. Lastly, some posts describe recent improvements in SQL Server, and the means to employ them best.

Simplify statements with IF

In some cases, a SQL statement can be simplified by using procedural logic.  Instead of issuing one complex query to cover multiple cases with UNION or OR, it is better to use and if..else logic to separate the cases into different SQL statements.  In this way, the optimizer optimizes multiple simpler statements instead of a single complex statement and may be able to get better performing plans for each case.

Published Thursday, November 10, 2005 2:00 PM by ianjo

Comments

 

msdngtnexus said:

Interesting. Care to give an example?

October 22, 2007 5:45 PM
 

Ian Jose s WebLog Simplify statements with IF | Paid Surveys said:

June 2, 2009 4:10 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker