title: In T-SQL, why is like operator not working for a variable but works for a literal?
body: <p>Here is the script:</p>
  
  <p>First script:</p>
  
  <pre><code>declare @a char(10) = 'AA%'
  declare @b char(10) = 'AA001'
  
  if @b LIKE @a 
       print 'Equals' 
  else 
  begin 
       print 'Not equals' 
  end
  </code></pre>
  
  <p>It prints:</p>
  
  <pre><code>Not Equals
  </code></pre>
  
  <p>I was expecting it to print <code>Equals</code>. But the script below which does not use <code>@a</code> in the condition:</p>
  
  <p>Second script:</p>
  
  <pre><code>declare @a char(10) = 'AA%'
  declare @b char(10) = 'AA001'
  
  if @b LIKE 'AA%' 
      print 'Equals' 
  else 
  begin 
      print 'Not equals' 
  end
  </code></pre>
  
  <p>prints</p>
  
  <pre><code>Equals
  </code></pre>
  
  <p>So why does the first script consider them not-equal but the second script consider them equal?</p>