/ (Divide) (TSQL Operator)

Divides one number by another number.

Syntax

expression / expression

Arguments

expression
is a numeric expression of type tinyint, smallint, int, bigint, money, numeric, float.

Return Types

Returns the datatype of the expression with the highest type precedence.

Remarks

If both expressions are integer numbers, an integer division is performed, which truncates the result to integer type.

If divisor is 0, an error is raised.

Examples

-- integer division, because both operands are integers
PRINT 123 / 50;

-- numeric division, because first operand is numeric type, and it has highest type precedence.
PRINT 123. / 50; -- second operand is cast to numeric type, and result is numeric type

-- float division, because first operand is float type, and it has highest type precedence.
PRINT 123.e0 / 50; -- second operand is cast to float type, and result is float type

-- varchar is converted to int, because int has highest type precedence
PRINT '123' / 50;

The result is:

2
2.460000000000
2.46
2

Example division by 0

PRINT 123.45 / 0;

The result is:

<Arithmetic error. NUMERIC division by zero.>
RSQL, a simple alternative to Microsoft SQL Server