Open In App

POWER() Function in SQL Server

Last Updated : 30 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

POWER() function :
This function in SQL Server is used to return a results after raising a specified exponent number to a specified base number. For example if the base is 5 and exponent is 2, this will return a result of 25.

Features :

  • This function is used to find a results after raising a specified exponent number to a specified base number.
  • This function accepts two parameters base and exponent.
  • The base value can be negative but not the exponent value.
  • The base and exponent value can be in fraction.
  • This function uses a formula
    “(base)
    (exponent) = Returned value”.

Syntax :

POWER(a, b)

Parameter :
This method accepts two parameters as given below :

  • a : Specified base number.
  • b : Specified exponent number.

Returns :
It returns a results after raising a specified exponent number to a specified base number.

Example-1 :
Getting a result of 49 for the base value 7 and exponent value 2.

SELECT POWER(7, 2);

Output :

49

Example-2 :
Getting a result of 27 for 3 as the base and exponent value.

SELECT POWER(3, 3);

Output :

 27

Example-3 :
Using POWER() function with variables and getting a result of 1 for the base value 6 and exponent value 0.

DECLARE @Base_Value INT;
DECLARE @Exponent_Value INT;
SET @Base_Value = 6;
SET @Exponent_Value = 0;
SELECT POWER(@Base_Value, @Exponent_Value);

Output :

1

Example-4 :
Getting a result of 0 for the base value 0 and exponent value 4.

SELECT POWER(0, 4);

Output :

0

Example-5 :
Getting a result of -64 for the base value -4 and exponent value 3.

SELECT POWER(-4, 3);

Output :

-64

Example-6 :
Using POWER() function with variables and getting a result of 28.2 for the base float value 2.1 and exponent float value 4.5.

DECLARE @Base_Value FLOAT;
DECLARE @Exponent_Value FLOAT;
SET @Base_Value = 2.1;
SET @Exponent_Value = 4.5;
SELECT POWER(@Base_Value, @Exponent_Value);

Output :

28.182974409756689

Application :
This function is used to return a results after raising a specified exponent number to a specified base number.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads