Saturday, April 22, 2017

POWER() in SQL Server


SQL ABS() function is used to return the value of the numeric expression raised to another numeric expression. POWER() takes 2 arguments i.e. base and exponent and returns the values of base raised to exponent. NULL values are not considered. POWER() does not work on non-numeric columns such as text.


Syntax:

     
            SELECT POWER(expression, power float)
           


  
     
            SELECT POWER(base, exponent)


base is the numeric value of which power value (number of times) is to be calculated.

exponent is the power to the base


Example 1:
POWER() on numeric column.

SELECT * FROM TempEmployeePayHistory




SELECT Rate, POWER(Rate) FROM TempEmployeePayHistory




Example 2:
POWER() on column with NULL values.

          SELECT * FROM TempEmployeePayHistory




SELECT Rate, POWER(Rate) FROM TempEmployeePayHistory




Example 3:
POWER() on text column.

          SELECT * FROM DatabaseLog




          SELECT [Event], POWER([Event]) FROM DatabaseLog



Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: