MS Access: Sgn Function
This MSAccess tutorial explains how to use the Access Sgn function with syntax and examples.
Description
The Microsoft Access Sgn function returns the sign of a number (represented as an integer).
Syntax
The syntax for the Sgn function in MS Access is:
Sgn ( number )
Parameters or Arguments
- number
- The number to return the sign for.
Note
- If number is greater than zero, the Sgn function will return 1.
- If number is equal to zero, the Sgn function will return 0.
- If number is less than zero, the Sng function will return -1.
Applies To
The Sgn function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example
Let's look at how to use the Sgn function in MS Access:
Sgn (-123.67) Result: -1 Sgn (0) Result: 0 Sgn (123.67) Result: 1
Example in VBA Code
The Sgn function can be used in VBA code in Microsoft Access.
For example:
Dim LResult As Integer LResult = Sgn (56)
In this example, the variable called LResult would now contain the value of 1.
Example in SQL/Queries
You can also use the Sgn function in a query in Microsoft Access.
For example:
In this query, we have used the Sgn function as follows:
Expr1: Sgn(3.25)
and
Expr2: Sgn([ReorderLevel])
The first Sgn function will return the sign of the value 3.25 and display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
For example:
SignValue: Sgn(3.25)
The results would now be displayed in a column called SignValue.
The second Sgn function will return the sign of the CategoryDate field and display the results in a column called Expr2.
Advertisements