In responses to this question, KM said
if you are on or above SQL Server 2005, you can use IFs to have multiple queries in the same procedure and each will have an query plan saved for it (equiv to a procedure for each on older versions), see the article in my answer or this link to proper section: sommarskog.se/dyn-search-2005.html#IF
HLGEM added
You can do that in earlier versions of SQL Server as well.
I read that section of Sommarskog’s excellent article but did not see anything about multiple plans.
In later research, I read a quote here from Gert Drapers:
Because SQL Server allows only one execution plan per stored procedure …
I don’t know the date of that original article or the version of SQL Server he is referring to.
Does anyone have a reliable reference that discusses this or, better yet, a test that proves that this is true?
We’re all correct 🙂
A “query plan” has at most 2 entries in cache: one serial and one parallel
Each user has their own “Execution context” that runs the plan
Plans differ if objects are not qualified
So, what you may think is a plan is not because tables are not qualified with schema (which is the same in SQL Server 2000 , 2005 and 2008)
From MSDN/BOL “Execution Plan Caching and Reuse“
Edit:
“Obtaining Statement-Level Query Plans” from MS blog