title: How to optimize the stored procedure code
body: <p>I have a stored procedure which accepts 5 input parameters. The columns which the stored procedure returns is the same, but where condition changes according the params passed in.</p>
  <p>Currently I'm using <code>if, else-if</code> to check for different conditions, and select the statements according to where conditions. Can anyone help me with other optimized way?</p>
  <p>Update: now I have almost 14 parameters and check the conditions with all possible combinations. Is there any way in SQL for this check, apart from giving all conditions explicitly?</p>
  <p>Here is the piece of stored procedure:</p>
  <pre><code>if(@OwnerWWID is null and @OwnerEmailID is null and @SourceURL is null and @ServerName is null and @Wave is not null)
  begin
      select distinct 
          mp.Id, mp.SourceURL,.......
      from
          dbo.MPlanner as mp with(nolock)
      where 
          mp.MigrationWave = @Wave
  end
  else if(@OwnerWWID is not null and @OwnerEmailID is null and @SourceURL is null and @ServerName is null and @Wave is null)
  begin
      select distinct 
          mp.Id, mp.SourceURL,.......
      from
          dbo.MPlanner as mp with(nolock)
      where  
          mp.OwnerWWID like @OwnerWWID + '%'
  end
  else if(@OwnerWWID is null and @OwnerEmailID is not null and @SourceURL is null and @ServerName is null and @Wave is null)
  begin
      select distinct  
          mp.Id, mp.SourceURL,.......
      from
          dbo.MPlanner as mp with(nolock)
      where 
          ((mp.[Document Library Owner Email IDs] like @OwnerEmailID + '%' 
            or mp.[Site Owner Email IDs] like @OwnerEmailID + '%' 
            or mp.SourceURL like @OwnerEmailID + '%' 
            or mp.UserEmailID like @OwnerEmailID + '%')
           and DestinationType = 'sp') 
          or ((mp.OwnerEmailID like @OwnerEmailID + '%' 
               or mp.SourceURL like @OwnerEmailID + '%' 
               or mp.UserEmailID like @OwnerEmailID + '%') 
              and mp.DestinationType = 'odfb' and mp.OwnerJJEDSStatus = 1)
  end 
  </code></pre>