Mike, I have tried with @i += a, exactly as it is documented there in the list of operators.
The result is the same as with @i = @i + a.
I believe your explanation regarding the importance of the ORDER BY place in the execution plan is the right one and this is what the SQL Server does in its depth.
If you accept my best feelings for clearly state this explanation, then kindly please let me express them. This is the kind of answer expected from a professional.
However, despite the accuracy of the answer, we can see that in one case the "last row" is the result of a computing, while in the other case the "last row" is taken without any calculation.
Meantime I have made more tests and if no ORDER BY at all then 6 is returned. My feeling is it must be something more here. Is there any chance that the reason why we see different results is the fact that ORDER BY occurs only after all the computings are done? Which means also that ofter ORDER BY no computing could be expected to occur?
I am simply trying to find a reason to accept this behavior as "intended", or "normal" or "that was supposed to be".
What is "normal" for operators like "+="? From the link I have indicated above, which is the connection between "+= Add and assign" and "the variable is assigned the last value that is returned"?
Wouldn't it be normal to always compute 0 + 3 which is the current value of the variable plus the value in the last row? Then why the value is 6 sometimes?
You are, again, right. Rude or offending response should not occur. If my post was rude (I have used "kindly please" to ask for a clear stated favor) why if a professional is posting an answer which is vaguely related to the problem is not even more rude and offending? I would greatly appreciate your answer as English is not my native language and it seems I am missing some point here.
No comments:
Post a Comment