title: Comparing with date or datetime columns in SQL server
body: <p>We are migrating from Oracle to SQL Server (using SSMA). In our Oracle environment, we were using the <code>DATE</code> datatype for some columns, during the datatype mapping for SQL Server we set <code>DATETIME</code> datatype for the corresponding columns.</p>
  
  <p>Now, suppose I have a table as follows:</p>
  
  <pre><code>+--------+-------------+---------------------------+
  | grn_id | grn_no      | grn_dt                    |
  +--------+-------------+---------------------------+
  | 1      | 0000000001  | 2018-01-03 00:00:00.000   |
  | 2      | 0000000002  | 2018-01-03 00:00:00.000   |
  | 3      | 0000000003  | 2018-01-03 00:00:00.000   |
  | 4      | 0000000001  | 2018-01-27 00:00:00.000   |
  +--------+-------------+---------------------------+
  </code></pre>
  
  <p>I'm trying to filter this data with <code>grn_dt(DATATYPE IS DATETIME)</code> with a string like <code>'2018-01-27'</code>. What is the right way to do this?</p>
  
  <p>We have already used a convert function as follows:</p>
  
  <pre><code>SELECT * FROM grn_header WHERE convert(date,grn_dt) &lt;= '2018-01-27'
  </code></pre>
  
  <p>Anyway, we are getting the required output, but is this conversion right?</p>
  
  <p>Do I have to set the conversion for the string (<code>'2018-01-27'</code>) also as follows?</p>
  
  <pre><code>SELECT * FROM grn_header WHERE convert(date,grn_dt) &lt;= convert(date,'2018-01-27') 
  </code></pre>
  
  <p>Is there any alternative way to do this?</p>