title: Is it possible to reuse aggregate functions results in the same select?
body: <p>look at this TSQL code:</p>
  
  <pre><code>SELECT A, B, C, (MAX(A) - MAX(B))*C AS 'myCalculatedColumn',
  dbo.[udf_GetBetaInv]((MAX(A) - MAX(B))*C, A, B, C) as 'BetaInv'
  FROM dbo.MyTable
  WHERE...
  </code></pre>
  
  <p>is there any way to have the block: <code>(MAX(A) - MAX(B))*C</code> written only once and used in the myCalculatedColumn definition and also as parameter of the udf in the same statement.</p>
  
  <p>I care mostly about performances, not sure if SQL Server calculates this once or multiple times but even if only once, would be better to have the SQL code more readable and compact and have only one place to modify in case we should change a formula.</p>
  
  <p>Edit. I was suggested to use CROSS APPLY recently for exactly same issue: <a href="https://stackoverflow.com/questions/9198062/simplify-sql-statement-by-using-cte">simplify SQL statement by using CTE</a></p>