I want to understand what is the best method for implementing the IF condition inside a stored procedure.
I saw how this method was widely used. 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, it creates a reusable query plan and fewer cache cache failures. Is it a fact or fiction? What is the right method to use.
Thank you in advance
source share