title: how to use convert function sql (String to Date)
body: <p>I have imported a calendar table from datameer over to my sql server database. I am fairly new to SQL so I do not have the best understanding of the convert function. I have a calendar table with 5 columns (cal_month, cal_year, Toronto, Montreal, National_Avg). The data types are (nvarchar, nvarchar, numeric, numeric, float). </p>
  
  <p>Example of a row in the table would be:</p>
  
  <pre><code>  Month  | Year | Toronto | Montreal | National Average
  ---------+------+---------+----------+------------------
   January | 2018 | 20      | 21       | 20.5
  </code></pre>
  
  <p>Below is my attempt at the convert function, my query is supposed to identify current month and -1 to grab the national average from the previous month so in this instance it would be for February 2018.</p>
  
  <pre><code>select convert(date, cal_month), convert(date,cal_year), National_Avg 
  from dbo.CALENDAR
  where month(cal_month) = month(dateadd(month,-1,current_timestamp))
               and year(cal_year) = year(dateadd(month,-1,current_timestamp))
  </code></pre>
  
  <p>The error I am receiving is:</p>
  
  <pre><code>Conversion failed when converting date and/or time from character string.
  </code></pre>