title: SQL Server : Join Ignores Leading Zeros
body: <p>My question is pretty straight forward, so I'm going to attempt asking it without making any dummy tables.</p>
  
  <p>Consider the case where I have two tables: A and B.  </p>
  
  <p>Suppose that A has <code>varchar</code> column <code>AVar</code> such that every element in <code>AVar</code> is a string of integers which do not begin with <code>0</code>.  </p>
  
  <p>Also suppose that B has a <code>varchar</code> column <code>BVar</code> such that the elements of <code>BVar</code> are identical to the entries in <code>AVar</code>, but have either 1 or 2 leading <code>0</code>'s in front of each entry.  </p>
  
  <p>For example "123454" in AVar would have a corresponding "0123454" or "00123454" in BVar</p>
  
  <p>When I perform the following query I find that my join runs successfully, even though the <code>varchar</code> elements within the two tables are technically not the same string values.</p>
  
  <p>What is happening under the hood that allows this comparison to be relaxed?</p>
  
  <pre><code>SELECT 
      A.AVar, B.BVar
  FROM 
      A 
  LEFT JOIN 
      B ON A.AVar = B.BVar
  </code></pre>