title: Using DATEDIFF within a SELECT
body: <pre><code>SELECT DISTINCT
      Test,
      FIRST_VALUE (CONVERT(DATE, datetime)) OVER (ORDER BY datetime DESC) StartDate,
      LAST_VALUE  (CONVERT(DATE, datetime)) OVER (ORDER BY datetime DESC) EndDate,
      DATEDIFF(MONTH, StartDate, EndDate)
  FROM
      Tests
  </code></pre>
  
  <p>Any ideas on how I can include the difference between the 2 dates within the SELECT?</p>
  
  <p>I want to be able to use the values StartDate and EndDate however I'm getting an error saying StartDate and EndDate are invalid columns.</p>