Access: Sgn Function

In Access, the Sgn function returns a variant indicating the sign of a number.

The syntax for the Sgn function is:

Sgn( number )

The argument number can be any valid numeric expression. Its sign determines the value returned by the Sgn function.

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 Sgn function will return -1.

Example

Sgn (2.38)       returns 1 
Sgn (0)          returns 0
Sgn (-2.38)      returns -1

VBA Code

Dim MyNumber As Integer 
MyNumber = Sgn(3.40)

This example uses the Sgn function to determine the sign of a number. Now the MyNumber variable would contain the value 1.

SQL query

You can also use the Sgn function in a query.

SELECT Sgn(-24.65) AS Expr1, Sgn([OwnerID]) AS Expr2 
FROM Orders
admin

admin

Leave a Reply

Your email address will not be published.