Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
SIN() and COS() Function in SQL Server
Next article icon

SIGN() Function in SQL Server

Last Updated : 27 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In SQL Server, the SIGN() function is a mathematical function used to determine the sign of a given numeric expression. This function is particularly useful when we want to evaluate whether a number is positive, negative or zero. In this article, We will learn about SIGN() Function in SQL Server in detail by understanding various examples

SIGN() Function in SQL Server

  • The SIGN() function in SQL Server is used to return the sign of a given numeric expression.
  • It indicates whether the number is positive, negative or zero by returning 1, -1 or 0 respectively.

Features of SIGN() Function in SQL Server

  • This function is used to find the sign of the given number i.e., that given number is positive or negative or zero.
  • This function accepts only all types of numbers i.e., positive, negative, zero.
  • This function also accepts fraction numbers.
  • This function always returns 1 if the number is positive, -1 if the number is negative and 0 for zero number.

Syntax:

SIGN(number)

Parameter:

This method accepts a parameter as given below :

  • number: Specified number to return the sign for.

Returns:

It returns the sign of the specified number.

Examples of SIGN() Function in SQL Server

Example 1:

Getting the result as 1 i.e., positive for the specified number 2.

SELECT SIGN(2);

Output:

1

Example 2:

Getting the result as -1 i.e., negative for the specified number -7.

SELECT SIGN(-7);

Output:

-1

Example 3:

Let’s Determine the sign of a numeric variable in SQL Server that holds the value 0 using the SIGN() function.

DECLARE @Parameter_Value INT;
SET @Parameter_Value = 0;
SELECT SIGN(@Parameter_Value);

Output:

0

Explanation: In this query, a variable @Parameter_Value is declared as an integer and assigned a value of 0. The SIGN() function is then used to evaluate the sign of this variable. Since the value is 0, the SIGN() function will return 0, indicating that the number is neither positive nor negative.

Example 4:

Getting the result as 1 i.e., positive for the result of “5/2”.

SELECT SIGN(5/2);

Output:

1

Example 5:

Using SIGN() function with a variable and getting the result as 1 i.e., positive for the float value “5.75”.

DECLARE @Parameter_Value FLOAT;
SET @Parameter_Value = 5.75;
SELECT SIGN(@Parameter_Value);

Output:

1.0

Conclusion

The SIGN() function in SQL Server provides a simple yet powerful way to determine the sign of any numeric value, whether it’s positive, negative, or zero. This function is versatile and works with all numeric types, making it ideal for scenarios where you need to quickly evaluate or categorize numbers in SQL queries.



Next Article
SIN() and COS() Function in SQL Server

K

Kanchan_Ray
Improve
Article Tags :
  • Databases
  • SQL
  • DBMS-SQL
  • SQL-Server

Similar Reads

  • SOUNDEX() Function in SQL Server
    The SOUNDEX() function in SQL Server is a powerful tool for handling phonetic matching, which allows you to compare words based on their sound rather than their exact spelling. This can be particularly useful in applications like searching and data cleansing where names or words may have different s
    3 min read
  • SIN() and COS() Function in SQL Server
    1. SIN() Function : The SIN() function returns the sine of a number. Syntax : SIN(number) Parameter : Required. A numeric value. number : It is a numeric value. Returns : It returns the float_expression of the sine of a number. Example-1 : When the argument holds a positive number. SELECT SIN(5); Ou
    1 min read
  • SQRT() Function in SQL Server
    SQRT() function : This function in SQL Server is used to return the square root of a specified positive number. For example, if the specified number is 81, this function will return 9. Features : This function is used to find the square root of a given number. This function accepts only positive num
    2 min read
  • SQL Server LEN() Function
    SQL SERVER LEN() function calculates the number of characters of an input string, excluding the trailing spaces. LEN() Function in SQL ServerThe LEN function in the SQL Server fetches the number of characters in a string. It counts the preceding spaces but not the trailing spaces. For eg, 'SQL SERVE
    2 min read
  • LOG() Function in SQL Server
    The LOG() function returns the logarithm of a specified number or the logarithm of the number to the specified base. Syntax : LOG(number, base) Parameter : LOG() function accepts two-parameters as mentioned above and described below. number - This parameter hold a number which is greater than 0. bas
    1 min read
  • DAY() Function in SQL Server
    DAY() function : This function in SQL Server is used to return the day of the month i.e, from 1st to 31st for date stated. Features : This function is used to find the day of the month for a date specified. This function comes under Date Functions. This function accepts only one parameter i.e, date.
    2 min read
  • STR() Function in SQL Server
    The STR() function converts a numeric value to a character value. Syntax : STR(float_expression [, length [, decimal]]) Parameter : This method accepts three parameters as mentioned above and described below : float_expression : It is a numeric expression that evaluates to an approximate number with
    1 min read
  • SUM() Function in SQL Server
    The SUM() function in SQL Server is an essential aggregate function used to calculate the total sum of values in a numeric column. It aggregates data by summing up all values in the specified column for the rows that match the criteria of the query. In this article, We will learn about SUM() Functio
    3 min read
  • SQL Server ISNULL() Function
    The ISNULL() function in SQL Server is a powerful tool for handling NULL values in our database queries. It allows us to replace NULL values with a specified replacement value, ensuring that your queries return meaningful results even when data is missing. In this article, We will learn about the SQ
    4 min read
  • IIF() Function in SQL Server
    IIF() function judges or evaluates the first parameter and returns the second parameter if the first parameter is true, otherwise, it returns the third parameter. IIF() function used in SQL Server to add if-else logic to queries.IIF is not supported in dedicated SQL pools in Azure Synapse Analytics.
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences