title: Filter dates stored as varchar in SQL Server
body: <p>I am using SQL Server 2008 R2 on the EC2 instance. I have a database having 4 fields of all varchar(50). </p>
  
  <pre><code> SELECT
   *
  FROM
   xyz
  WHERE
   DataDate ='20140609'
  </code></pre>
  
  <p>This query gives no result.</p>
  
  <pre><code>SELECT
   *
  FROM
   xyz
  WHERE
   DataDate = (Select MAX(DataDate) from xyz)
  </code></pre>
  
  <p>This query runs perfectly.</p>
  
  <pre><code>Select MAX(DataDate) from xyz 
  </code></pre>
  
  <p>This query results in 20140609.</p>
  
  <p>I cannot understand why this this happening. Can someone please explain this?</p>