Hello,
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.
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.
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).
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?
Thanks.
Anonymous.