I want to understand which is the better method of implementing a "IF" condition inside a stored procedure.
I have seen this method used extensively. Which is comparable to iterative coding...
declare @boolExpression bit = 1 --True
if @boolExpression = 1
select column from MyTable where group = 10
else
select column from MyTable where group = 20
I prefer to use a set based method...
declare @boolExpression bit = 1 --True
select column from MyTable where group = 10 and @boolExpression =1
union all
select column from MYTable where group = 20 and @boolExpression =0
I prefer to use this method because as I understand it creates a re-useable query plan and less plan cache churn. Is this fact or fiction? Which is the correct method to use.
Thanks in advance