title: Using DATEDIFF in T-SQL
body: <p>I am using DATEDIFF in an SQL statement.  I am selecting it, and I need to use it in WHERE clause as well.  This statement does not work...</p>
  
  <pre><code>SELECT DATEDIFF(ss, BegTime, EndTime) AS InitialSave
  FROM MyTable
  WHERE InitialSave &lt;= 10
  </code></pre>
  
  <p>It gives the message: <em>Invalid column name "InitialSave"</em></p>
  
  <p>But this  statement works fine...</p>
  
  <pre><code>SELECT DATEDIFF(ss, BegTime, EndTime) AS InitialSave
  FROM MyTable
  WHERE DATEDIFF(ss, BegTime, EndTime) &lt;= 10
  </code></pre>
  
  <p>The programmer in me says that this is inefficient (seems like I am calling the function twice).  </p>
  
  <p>So two questions.  Why doesn't the first statement work?  Is it inefficient to do it using the second statement?</p>