Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,913 of 19,505    |
|    Lennart Jonsson to Dom    |
|    Re: The order of executing a wIndowing F    |
|    17 Sep 10 20:39:33    |
      8c401eec       From: erik.lennart.jonsson@gmail.com              On 2010-09-17 18:10, Dom wrote:       > I was always told that the order of execution in T-SQL was FROM,       > SELECT, WHERE. This turns out to be important if you want to avoid       > certain errors, such as "divide by zero" error.       >       > But now look at the following table:       >       > ID Name Pos       > 1 Dom 1       > 1 Kim 2       > 1 Sam 3       >       >       > In the following, it looks like the windowing function is done AFTER,       > not BEFORE, the where clause:       >       >       > select Name, max (Pos) over (partition by Group_ID)       > from T_Table       > where Last_Name < 'S'       >       > The value for max (Pos) is 2, not 3.       >       > Why did that happen?              I don't see anything controversial about that. What do you expect from a       query like:              select Id, max (Pos)       from T_Table       where Last_Name < 'S'       group by Id              1,3 or 1,2?              If you want to investigate how it is defined (not exactly a walk in the       park though :-), you can download draft documents of the standard from:              http://www.wiscorp.com/SQLStandards.html              For the 2003 variant the relevant document is named       5WD-02-Foundation-2003-09.pdf                     /Lennart              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca