title: sql - datetime variable versus string representation of datetime variable
body: <p>I have a query that takes too long to respond when the search parameter happens to be a varchar datatype with date. However, if i convert varchar to datetime variable, the query runs fine.  For ex:</p>
  
  <p>This takes too long.</p>
  
  <pre><code>select count(id)
    from names
   where updateddate &gt; '1/5/2010'
  </code></pre>
  
  <p>This runs fine.</p>
  
  <pre><code>declare @dateparam datetime
      set @dateparam = convert(datetime, '1/5/2010',102)
  
  select count(id)
    from names
   where updateddate &gt; @dateparam
  </code></pre>
  
  <p>What's the reason one runs fine but the other doesn't?</p>