title: Does SQL Server optimize LIKE ('%%') query?
body: <p>I have a Stored Proc which performs search on records.</p>
  
  <p>The problem is that some of the search criteria,which are coming from UI, may be empty string.
  So, when the criteria not specified, the LIKE statement becomes redundant. </p>
  
  <p>How can I effectively perform that search or Sql Server? Or, Does it optimize LIKE('%%') query since it means there is nothing to compare?</p>
  
  <p>The Stored proc is like this:</p>
  
  <pre><code>ALTER PROC [FRA].[MCC_SEARCH]
  @MCC_Code varchar(4),
  @MCC_Desc nvarchar(50),
  @Detail nvarchar(50)
  AS
  BEGIN             
         SELECT
               MCC_Code,
               MCC_Desc,
               CreateDate,
               CreatingUser
  
         FROM
                FRA.MCC (NOLOCK)
         WHERE
               MCC_Code LIKE ('%' + @MCC_Code + '%')
               AND MCC_Desc LIKE ('%' + @MCC_Desc + '%')
               AND Detail LIKE ('%' + @Detail + '%')
         ORDER BY MCC_Code
  
  END
  </code></pre>