>>>>As a follow-up, the "why" is becuase the result (with the alias name) hasn't been created.....
>>>>
>>>>That's why you can use expression aliases in an ORDER BY....becuase the result set has already been created (sort of), and the database engine can refer to any alias names. But prior to that (i.e. in a GROUP BY), it's too early to use aliases.
>>>
>>>Now I see.
>>>
>>>For instance, you can use Row_Number() result in ORDER BY but not in the WHERE expression, AFAIK.
>>
>>I have in my notes processing in this order (my notes are old though so it may not be true anymore):
>>
>>1. From clause
>>2. Where clause
>>3. Group By Clause
>>4. Having Clause
>>5. Select clause (this is where the alias names come to 'be.')
>>(Left out order by which is operated on the cursor so it would be #6)
>>
>>Can anyone update it? Is it different now? This is from 2004.
>
>Here is a nice poster by Itzik Ben-Gan
>
>
http://www.solidq.com/insidetsql/books/insidetsql2008/Logical%20Query%20Processing%20Poster.pdfNice thanks! (However, next time you might want to warn before others click on the link when the filesize is > 1mb) :o)
.·*´¨)
.·`TCH
(..·*
010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"