February 22, 2012 at 3:13 am
Hi all,
I'm wondering if there's a way to reuse a "just declared" alias, rather than having to express the whole equation that underpinned it again. Example,
SELECT 100*SUM(greg) / AVG(steve) as Number1, Number1 * 2 as Number2 FROM...
This is what I'd like to do. Rather than...
SELECT 100*SUM(greg) / AVG(steve) as Number1, 100*SUM(greg) / AVG(steve) * 2 as Number2 FROM...
Obviously it gets worse when in real life a value is generated by a more complex equation.
Regards, Greg.
February 22, 2012 at 3:33 am
Have a look here
http://www.sqlservercentral.com/Forums/Topic1248957-392-1.aspx
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537February 22, 2012 at 5:53 am
Thanks, I guess not. Intersting critique which I didn't agree with.
Of course SQL could do this if "it" wanted to.
The order of the items in the select list is significant.
I'm not a purist anyway, I like practical solutions !
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply