SQL SERVER – Math Functions for 2005

The large majority of math functions are specific to applications using trigonometry, calculus, and geometry. This are very important and it is very difficult to have all of them together at place.

Math Functions

Absolute value ABS
Arc cosine ACOS
Arc sine ASIN
Arc tangent of n ATAN
Arc tangent of n and m ATN2
Smallest integer >= value CEILING
Cosine COS
Hyperbolic cosine COT
Exponential value EXP
Round down to nearest integer FLOOR
Natural logarithm LOG
Logarithm, base 10 LOG10
Modulus (remainder) USE MODULO (%) OPERATOR
Power POWER
Random number RAND
Round ROUND
Sign of number SIGN
Sine SIN
Square root SQRT
Tangent TAN
Convert number if NULL ISNULL
Standard deviation STDEV
Variance VAR

Reference : Pinal Dave (http://blog.SQLAuthority.com) , BOL Math Functions

7 thoughts on “SQL SERVER – Math Functions for 2005

  1. is there a way to do a division and modulo in the same statement? I’d like the result of the division to go into one variable and the remainder into another.

    Like

  2. How to get highest value from 5 local variables in a stored procedure.
    Eg:
    Declare @var1 as int, @var2 as int, @var3 as int, @var4 as int, @var5 as int
    Set @var1=55
    Set @var2=70
    Set @var3=90
    Set @var4=90
    Set @var5=25

    I need value distinct 90 as it is highest among all variables. I mentioned distinct because it repeats in @var3 and @var4 both.

    Thanks

    Like

    • create table temp(col1 integer)
      select * from temp

      DECLARE @temp TABLE(col1 INTEGER)
      DECLARE @r int=55
      DECLARE @s int=70
      DECLARE @t int=90
      DECLARE @q int=70
      DECLARE @x int=90
      INSERT INTO temp(col1) values(@r)
      INSERT INTO temp(col1) values(@s)
      INSERT INTO temp(col1) values(@t)
      INSERT INTO temp(col1) values(@q)
      INSERT INTO temp(col1) values(@x)

      SELECT MAX(col1) FROM temp

      Like

  3. SQUARE() Float expression

    Square of the given numeric expression. Equivalent of POWER function when raised to 2nd power. Example:

    SELECT SQUARE(3)
    9

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s