title: Using list alias in WHERE or GROUP BY clause
body: <p>I'm writing a stored procedure containing SQL Select queries with some functions on some columns and a GROUP BY clause.
  Obviously, I have to repeat these functions in the GROUP BY, which dramatically decreases code readability and increases redundancy.</p>
  
  <p>So far, an alternative I have found was to use a derived query so I can access the alias names defined in the "second-level" query from the "top-level" query.
  I was moderately happy with this workaround as it increases code complexity (and indentation) and I feel that I shouldn't have to use two queries when I can return all the data I want using a single one.</p>
  
  <p>I've googled a bit and I found this page which returns the same tip about the subquery (+ one about creating a view but that's overkill in most cases).</p>
  
  <p><a href="http://databases.aspfaq.com/database/how-do-i-use-a-select-list-alias-in-the-where-or-group-by-clause.html" rel="nofollow noreferrer">http://databases.aspfaq.com/database/how-do-i-use-a-select-list-alias-in-the-where-or-group-by-clause.html</a></p>
  
  <p>I can't seriously believe that in 2010, there is no other way, especially with all the focus on code reusability and readability that has been going on for some years: would anyone have an elegant tip I never heard ever heard of (for SQL Server 2005/2008), or have an educated guess at why things should still be done that way in 2010?</p>
  
  <p>Thanks.</p>
  
  <p>Anonymous.</p>