Home > T-SQL > SQL SERVER – POWER() – SQL Math Functions @SQLSERVER

## SQL SERVER – POWER() – SQL Math Functions @SQLSERVER

Power() function is used to calculate xn  value. The return type of this function is same as float expression type.

Syntax:

Power(float expression, power value)

Example

select power(10, 3)
Output: 1000

select Power(-12, 2)
Output: 144

select power(2, 0)
Output: 1

select Power(1.3, 6)
Output: 4.8

T-SQL code to print a series of value for 2n

declare @i as int = 1
declare @n as int = 10
declare @x as float = 2.0

while @i <= @n
begin
print  ‘Power(‘+ cast(@x as varchar(3)) + ‘, ‘+ cast(@i as varchar(2)) + ‘) = ‘
print power(@x, @i)
set @i = @i +1
end

Output:
Power(2, 1) =
2
Power(2, 2) =
4
Power(2, 3) =
8
Power(2, 4) =
16
Power(2, 5) =
32
Power(2, 6) =
64
Power(2, 7) =
128
Power(2, 8) =
256
Power(2, 9) =
512
Power(2, 10) =
1024

So, we learned to compute x^n using T-SQL POWER() function today. Thanks for reading and I will meet you with another math function tomorrow.