looking for a brokerage account or IRA... click here Add To Favorites
return to index 

SQL OPTIMIZE FOR Query Hint

If you have ever written a stored procedure that used parameters in the SQL to execute and wondered why the execution plan was not ideal, then this may help.

As stupid as this sounds, SQL cannot take the declared variable type and figure out what indices to use.

To get around that, you can use OPTIMIZE FOR to provide a sample value for a parameter so that it can get a better execution plan.

Add the following code, an example is provided, at the end of the statement (after the group by / order by / etc.)

OPTIONS (OPTIMIZE FOR (@BeginTime = '2009-09-09'))

A great resource for this information is Click here for more information

Additional Interesting Articles

C# Needle In Haystack String Replacements
SQL Difference Between IS NULL and =NULL
AOL Email Delivery: Technical Standards
Email Delivery at AOL
Convert Quoted Printable to 8Bit
Execute Files Remotely Using PSExec

©2008 AndrewKimball.com