I am going to dig in and write another short article or tidbit on Transaction SQL math functions. Most, if not all, of these functions have been in the product before the release of SQL Server 2005.
I am very proud of my daughter making the advance math class in sixth grade. I am dedicating these blogs to her hard class work and love of the subject.
I will be exploring the SQUARE() function today.
This function takes a number N as input in either exact numeric or approximate numeric form. This does not include the BIT data type. The output of the function is the result of multiplying N times itself.
The example below tests the function with three different inputs: exact negative number, approximate numbers and a NULL value as arguments. I also demonstrate that the POWER() function can be used in place of the SQUARE() function.
1 2 3 4 5 6 7 8 9 10 11 |
-- -- The SQUARE Function -- -- Various numbers as input SELECT SQUARE(-5) AS POWER_TWO0, SQUARE(10.45) AS POWER_TWO1, POWER(10.4500, 2.000) AS POWER_TWO2, SQUARE(NULL) AS UNKNOWN; GO |
The output from the test is listed below.
1 2 3 4 5 |
output: POWER_TWO0 POWER_TWO1 POWER_TWO2 UNKNOWN -------------- -------------- -------------- ----------- 25 109.2025 109.2025 NULL |
In short, the SQUARE algebra function is the result of multiplying a number, or other expression, by itself. Next time I will be talking about square roots.