title: T-SQL varchar comparison question
body: <p>I'm using MS Sql 2005.</p>
  
  <p>Why does this give me the correct results (returns 169 rows)...</p>
  
  <pre><code>select
    * 
  from 
    [import_Data] 
  where 
    [import_Data].name not in 
    (
      select 
        [import_Data].name 
      from 
        [import_Data] 
        inner join [resource] on [import_Data].name = [resource].name
      where 
        [import_Data].ProviderTypeID = 4 
        and [resource].IsDeleted = 0
    )
    and [import_Data].ProviderTypeID = 4
  </code></pre>
  
  <p>But this doesn't (returns 0 rows)...</p>
  
  <pre><code>select 
    * 
  from 
    [import_Data] 
  where 
    [import_Data].name not in 
    (
      select 
        [resource].name 
      from 
        [resource] 
      where 
        IsDeleted = 0
    ) 
    and [import_Data].ProviderTypeID = 4
  </code></pre>
  
  <p>The only difference between the <code>name</code> columns is that <code>[resource].name</code> is <code>varchar(500)</code> and <code>[import_Data].name</code> is <code>varchar(300)</code>. </p>