title: Error: DATEPART does not exist, frp, SQL to select last months records
body: <p>I'm trying to get an SQL query to select all records from last month, I have this which from looking numerous places is exactly what I should need, and should work:</p>
  
  <pre><code>SELECT *
  FROM orders
  WHERE DATEPART(yy,DateOrdered) = DATEPART(yy,DATEADD(m,-1,GETDATE()))
  AND DATEPART(m,DateOrdered) = DATEPART(m,DATEADD(m,-1,GETDATE()))
  </code></pre>
  
  <p>However I keep getting the error:</p>
  
  <pre><code>#1305 - FUNCTION retail.DATEPART does not exist
  </code></pre>
  
  <p>The query I'm using is word for word from other answers on here, yet I'm getting this error. </p>
  
  <p>Thank you for any help -Tom</p>