An example of SQLServer2012 mathematical function

Source: Internet
Author: User
Tags abs acos asin cos natural logarithm rand sin square root

1 absolute Value function abs (x)

Cases:

SQL query:

?
1 SELECT ABS ( -1), ABS (0), ABS (1)

Execution results:

2 square root function sqrt (x)

Cases:

SQL query:

?
1 SELECT SQRT (4), SQRT (16)

Execution results:

3 random function rand (), rand (x)

Cases:

SQL query:

?
1 SELECT rand (), RAND (10)

Execution results:

Description

The random functions rand () and rand (x) return a 0~1 random floating-point number (containing 0 and 1).

If you specify a parameter x, it is used as a seed value to produce a random number. If the same seed value is used, the resulting random number is the same.

Cases:

SQL query:

?
1 SELECT Rand, rand (10)

Execution results:

4 Rounding function round (x,y)

Cases:

SQL query:

?
1 SELECT ROUND (32.12456,-1), ROUND (32.12456,0), ROUND (32.12456,1), ROUND (32.12456,2)

Execution results:

Description

Parameter x is the object of the rounding operation, and Y is the number of digits after which the decimal point is preserved.

When y is a negative integer, the position is retained to the front of the decimal point, as in the example-1 represents the digits reserved to the 1 digits before the decimal point (single-digit).

5 Power Operational function (X,y), SQUARE (x), EXP (x)

Cases:

SQL query:

?
1 2 3 Select Power (2.0,-1), Power (2.0,0), Power (2.0,1) Select Square ( -2.0), square (0), Square (2.0) SELECT exp ( -2.0), exp (0), EXP (2.0)

Execution results:

Description

Power (X,y) Returns the result value of the Y-second side of X.

Square (x) returns the square value of x.

EXP (x) Returns the result value of the X-second side of E.

6 Logarithmic operation log (x), LOG10 (x)

Cases:

SQL query:

?
1 2 Select log (1), log (EXP (1)) Select LOG10 (1), LOG10 (Ten), LOG10 (1000)

Execution results:

Description

Log (x) returns the natural logarithm, which is illustrated by the log (EXP (1)) return value 1 in the instance.

LOG10 (x) returns the logarithm of x with a base of 10.

7 Symbolic function sign (x)

Cases:

SQL query:

?
1 SELECT SIGN ( -1), SIGN (0), SIGN (1)

Execution results:

Description

SIGN (x) returns the symbol of x, returning 1 when X>0 returns 1,x=0 when returning to 0,x<0.

8 angle, Radian interchange function radians (x), DEGREES (x)

Cases:

SQL query:

?
1 2 Select RADIANS (90.0), RADIANS (180.0), RADIANS (360.0) Select DEGREES (Pi ()/2), DEGREES (Pi ()), DEGREES (Pi () *2)

Execution results:

Description

RADIANS (x) returns the Radian value of x, and DEGREES (x) Returns the value of the angle corresponding to X.

The Pi () function in the example returns PI.

9 sine function sin (x), Inverse chord function asin (x)

Cases:

SQL query:

?
1 SELECT sin (PI ()/2), sin (0), ASIN (1), ASIN (0)

Execution results:

Description

Sin (x) returns the sine of X, and ASIN (x) returns the inverse chord value of x.

10 chord function cos (x), inverse cosine function acos (x)

Cases:

SQL query:

?
1 SELECT COS (PI ()), cos (0), ACOS ( -1), ACOS (1)

Execution results:

Description

COS (x) returns the cosine of x, and ACOS (x) returns the inverse cosine of x.

11 Tangent function tan (x), Inverse tangent function atan (x), cotangent function cot (x)

Cases:

SQL query:

?
1 SELECT TAN (Pi ()/4), Atan (1), COT (Pi ()/4)

Execution results:

Description

TAN (x) returns the tangent value of x, Atan (x) returns the inverse tangent of x, and COT (x) returns the cotangent value of x.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.