title: Converting YYYYMM format to YYYY-MM-DD in SQL Server
body: <p>I need to perform a query on a large table that has a <code>datetime</code> column that is indexed. 
  We need to query the data for a range from a month (at a minimum) to multiple months. </p>
  
  <p>This query would be executed from Cognos TM1 and the input would be a period like <code>YYYYMM</code>. My question is - how to convert the <code>YYYYMM</code> input to a format that can be used to query that table (with the index being used). </p>
  
  <p>Let's say if the input is </p>
  
  <ul>
  <li>From Date: '201312'</li>
  <li>To Date:  '201312'</li>
  </ul>
  
  <p>then, we need convert the same to 'between 01-12-2013 and 31-12-2013' in the query</p>
  
  <p>Since we need this to be hooked up in Cognos TM1, so would not be able to write a procedure or declare variables (TM1 somehow does not like it). </p>
  
  <p>Thanks in advance for your reply.</p>