SQL POWER Function

This SQL Mathematical Function is used to calculate the power for the specified expression or numerical value, and its syntax is

SELECT POWER (Float_Expression, Value)
FROM [Source]

SQL POWER Function Example

This math Function calculates the power of a given numeric value. The following query shows multiple ways to use it.

First, we declared a float variable, and we used it to calculate the power of the variable @i. It means, @i * @i * @i = 2 * 2 * 2 = 8. In the next SQL Server statement, we used 4 as the second argument. It means 2 * 2 * 2 * 2 = 16

We used the integer value as the SQL Power function input within the first two select statements. It means, (@j, 3) = @j * @j * @j => 2.20 * 2.20 * 2.20 = 10.65. But we are getting 8 as a result because it is rounding the 2.20 value to 2

DECLARE @i float = 2, @j int = 2.20

SELECT POWER(@i, 3) AS [SQLPowers]

SELECT POWER(@i, 4) AS [SQLPowers]

-- Calculating directly
SELECT POWER(3.20, 3) AS [SQLPowers]

-- Wrong Value
SELECT POWER(@j, 3) AS [SQLPowers]
SELECT POWER(2.20, 3) AS [SQLPower]

NOTE: Use float variables as this Mathematical Function input. Otherwise, you may expect strange results.

The Sql Server Function also allows you to calculate the power of column values. In this example, We are going to calculate the power of three for all the records present in [Sales Amount]. For this demo, we use the below table data

Source Table 1
SELECT [EnglishProductName]
      ,POWER([SalesAmount], 3) AS Sales
 FROM [Mathemetical Functions]