dcsimg
 

Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Thursday Nov 8th 2018 by M S Sridhar

Language: SQL, Expertise: Beginner - See how to learn the sign of the number for computation purposes.

For a given number, it may be necessary to know the sign of the number for computation purposes.

If it is positive, zero or negative, you may have respective case to work on. The signs are returned as 1, 0, -1 for positive number, zero and negative number respectively.

Case 1: Positive number

SELECT SIGN(234) AS SIGN;
where 234 is the value. 

+-------+
| SIGN  |
+-------+
|    1  |
+-------+

Case 2: Number is zero

SELECT SIGN(0) AS SIGN;
where 0 is the value. 

+-------+
| SIGN  |
+-------+
|    0  |
+-------+

Case 3: Negative number

SELECT SIGN(-64500) AS SIGN;
where -64500 is the value. 

+-------+
| SIGN  |
+-------+
|   -1  |
+-------+ 
Home
Mobile Site | Full Site