title: SQL - How to exclude negative values from datediff function
body: <p>How do I exclude all datediff values that are negative from my average statement?</p>
  
  <p>query:</p>
  
  <pre><code>select Avg_DayDiff case when Avg_DayDiff &gt; 0
  
  from(
  
  SELECT DATEDIFF(DAY, xx, yy) AS Avg_DayDiff
  
  FROM Database1.dbo.tbl_1
  
  where  
          month(datecompleted) = month(dateadd(month,-1,current_timestamp))
         and year(datecompleted) = year(dateadd(month,-1,current_timestamp))
         and ApprovalRequiredFrom = 'GRM'
  
         ) temptable
  </code></pre>
  
  <p>My query returns a syntax error from my first line (select statement) I am still learning so any tips are greatly appreciated!</p>
  
  <p>the result I am looking for is to only return datediff if the # > 0, so then I can average it.</p>
  
  <p>thanks</p>