April 3, 2012 at 1:06 am
Dear All,
May I know why these output differs.
1.SELECT 30.0/(-2.0)/2.0
2.SELECT 30.0/-2.0/2.0
Always appreciating your helps.
April 3, 2012 at 5:06 am
it should be because of the precedence getting changed using the brackets.
http://blog.sqlauthority.com/2012/04/01/sql-server-a-puzzle-illusion-confusion-april-fools-day/
April 3, 2012 at 5:28 am
That's a good one. It looks like the minus sign is reversing the division, creating a multiplication when is then divided, unless you set the parenthesis so that it's a negative number. Never seen the like.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
April 3, 2012 at 5:57 am
I posted the question on twitter (#sqlhelp) to get some more feedback. This is anticipated behavior (at least according to Microsoft). You can see it in this Connect item.
Basically it doesn't work from left to right. Instead it evaluates -2/2 as -1 and then divides 30 by -1 which results in -30.
Not what I expected either.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply