- (負) (SQL Server Compact)

傳回數值運算式之負值的一元運算子。

語法

- numeric_expression

引數

  • numeric_expression
    MicrosoftSQL Server Compact 中的任何有效運算式,都屬於任何數值資料類型,但是 datetime 資料類型除外。

結果類型

傳回 numeric_expression 的資料類型,但是不帶正負號的 tinyint 運算式會提升至帶正負號 smallint 結果。

範例

以下範例顯示正號與負號的一元運算子如何運作。對負值加上正一元運算子時,傳回的值為負 (positive_value * negative_value = negative_value)。對負值加上負一元運算子時,傳回的數值為正 (negative_value * negative_value = positive_value)。

SELECT -(DATEPART(day, Order Date) - DATEPART(day, Shipped Date)) 
FROM Orders 
WHERE OrderID = '10248'
-- With the negative unary operator, the value returned is '12'.

SELECT (DATEPART(day, Order Date) - DATEPART(day, Shipped Date)) 
FROM Orders 
WHERE OrderID = '10248'
-- Without a unary operator, the value returned is '-12'.

SELECT +(DATEPART(day, Order Date) - DATEPART(day, Shipped Date)) 
FROM Orders WHERE OrderID = '10248'
-- With the positive unary operator, the value returned is '-12'.