/ (Divide) (U-SQL)

Summary

Divides one number by another (an arithmetic division operator).

Syntax

Divide_Operator :=                                                                                       
    dividend '/' divisor.

Remarks

Return Type

Returns the data type of the argument with the higher precedence. If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

Examples

  • The examples can be executed in Visual Studio with the Azure Data Lake Tools plug-in.
  • The scripts can be executed locally. An Azure subscription and Azure Data Lake Analytics account is not needed when executed locally.

Divide with Numeric Types

@data = 
    SELECT * FROM 
        ( VALUES
        ((int)25)
        ) AS T(aNumber);

DECLARE @val int = 5;

@result =
    SELECT 25 / 5 AS Int1,
           aNumber / 5 AS Int2,
           aNumber / @val AS Int3,
           aNumber / 3 AS truncatedResult,
           aNumber / 3.0 AS toDouble,
           aNumber / (int?)null AS intNull           
           // aNumber / 0 AS divideByZero  // will error
    FROM @data;

OUTPUT @result
TO "/ReferenceGuide/Operators/Arithmetic/Divide1.txt"
USING Outputters.Csv();

See Also