title: Using LIKE in sp_executesql
body: <p>SET @whereCond = @whereCond + ' AND name LIKE ''%'' + @name + ''%''' </p>
  
  <p>Is there something wrong here? After I generate where condition, I execute it with <code>sp_executesql</code>, but I did get anything. When I SELECT the same thing without sp, it's ok.</p>
  
  <p>How to use LIKE in sp_executesql? Can you bring some examples, please?</p>
  
  <p>Thank you.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>declare @name nvarchar(50)
  
  set @name = 'a'
  
  SELECT *
      FROM Tbl_Persons WHERE 1 = 1  AND lastname LIKE '%a%' 
  
  exec sp_executesql 
    N'SELECT *
      FROM Tbl_Persons WHERE 1 = 1  AND lastname LIKE ''%@name%''', 
    N'@name nvarchar(50)',
    @name=@name
  </code></pre>
  
  <p>First query returns values, second one doesn't return anything.</p>
  
  <p>What's the difference?</p>