title: Does calling a scalar function in a select statement multiple times run the function multiple times, and how to get around that if so
body: <p>If I have a select statement with a scalar function in it used in various calculations, does that scalar function get called multiple times? If it does, is there a way to optimize this so it only calls the funciton once per select, as in my real query it will be called thousands of times, X 6 times per select.</p>
  
  <p>For example:</p>
  
  <pre><code>SELECT 
  [dbo].[fn_Days](@Account) + u.[DayRate],
  [dbo].[fn_Days](@Account) / u.[WorkDays]
  FROM [dbo].[tblUnit] u
  </code></pre>
  
  <p>All fn_days does is return an int of days worked.</p>