Unary Negative in MS SQL

Occurred that  MS SQL also is not so perfect. Recently I was pointed to rsdn.ru where was shown a mathematical feature of the MS SQL:

ref A. SELECT 20.0 / -2.0 / 5.0 * 3.0 results into -16.666666

ref B. SELECT 20.0/ (-2.0) / 5.0 * 3.0 results into -6.00000

From my point of view (and I hope from math point also) both of results should be -6. But MS SQL recognizes “-” (minus) as a unary operator with higher priority. It executes from -2 until the end and then divides 20 with a calculated result:

ref A. 20 / ( -2 / 5 * 3)

ref B. 20 / -2 / 5 /3
This entry was posted in Microsoft SQL Server. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s