Hi,
As much as mathematically speaking SIGN(@value) * @value
will return the same as ABS(@value)
Regarding performance, I am not sure that you can notice difference in the client side even if there was any different algorithm behind he scenes.
By the way, Theoretically using the function SIGN on DECIMAL is totally different from using on INTEGER.
(Level 550 internals discussion)
Behind the scene SQL Server stores negative DECIMAL in a ones' complement
system while negative INTEGER are stored on Two's complement
. In short this means that the binary value of negative DECIMAL is exactly like the positive value except one bit, while negative value of INTEGER looks totally different.
For example: The value which is stored for the number one when using data type SMALLINT is 0000000000000001, but the value for minus ONE is 1111111111111111
SELECT CONVERT(BINARY(2), CONVERT(SMALLINT,1))
-- 1 : 0x0001 : 0000000000000001
SELECT CONVERT(BINARY(2), CONVERT(SMALLINT,-1))
-- -1 : 0xFFFF : 1111111111111111
You can read more about what Two's complement
means here: https://en.wikipedia.org/wiki/Two's_complement
And the value which is stored for the number one when using data type DECIMAL:
SELECT CONVERT(BINARY(7), CONVERT(DECIMAL(5,2),1))
-- 1 : 0x05020001640000
SELECT CONVERT(BINARY(7), CONVERT(DECIMAL(5,2),-1))
-- -1 : 0x05020000640000
-->> First byte on the left is the precision (5) and the second byte is the scale (2)
-- These two bytes are not store in a table!
-- They are only used when using the value on the fly.
-- The number value starts from byte 3
-->> SQL Server stores the decimal number (the integer part and the fraction part) without seperating of the decimal separator. For example the number 1.23 will be stored exactly like the number 123
-- Using DECIMAL(5,2) the number 1 is the same as 1.00 which means that SQL Server stores 100
--> 100 in binary is 64 in Hex
--> The number 1 before the "64" in 0x05020001640000
indicate that this is positive number
Therefore,
In both cases (INT and DECIMAL) we can find the sign of the number by reading a single bit but changing the SIGN of DECIMAL is done simply by changing one bit which indicate that this value is negative while changing the SIGN on INTEGER means that we need to calculate the entire BIT value. Using ABS(@Value) we can have one calculation but using sign(@value) * @value
we need to find the SIGN and calculate the change in sign.