- (Subtract) (U-SQL)
Summary
Subtracts two numbers (an arithmetic subtraction operator). Can also calculate date and time differences.
Syntax
Subtract_Operator := expression '-' expression.
Remarks
Return Type
Returns the data type of the argument with the higher precedence.
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.
Subtract with Numeric Types
@data =
SELECT * FROM
( VALUES
(38)
) AS T(aNumber);
DECLARE @val int = 5;
@result =
SELECT 38 - 5 AS Int1,
aNumber - 5 AS Int2,
aNumber - @val AS Int3,
aNumber - (int?)null AS intNull
FROM @data;
OUTPUT @result
TO "/ReferenceGuide/Operators/Arithmetic/Subtract1.txt"
USING Outputters.Csv();
Subtract with Temporal Types
@data =
SELECT * FROM
( VALUES
(new DateTime(2016,05,31))
) AS T(aDate);
@result =
SELECT aDate - new System.TimeSpan(1, 0, 0, 0) AS date1,
(new TimeSpan(1, 0, 0, 0) - new TimeSpan(0, 1, 0, 0)).ToString() AS date2,
(aDate - new DateTime(2016,05,1)).Days AS date3
FROM @data;
OUTPUT @result
TO "/ReferenceGuide/Operators/Arithmetic/Subtract2.txt"
USING Outputters.Csv();
See Also
- Operators (U-SQL)
- [Date & Time](../csharp-functions-and-operators.md#Date & Time)
- Simple Built-In U-SQL Types