+ (正) (SQL Server Compact)
為一元運算子,傳回數值運算式的正值。
語法
+ numeric_expression
引數
- numeric_expression
SQL Server Compact 4.0 中屬於數值資料類型類別目錄之任何一種資料類型的任何有效運算式,但是 datetime 資料類型除外。
結果類型
傳回 numeric_expression 的資料類型,但是不帶正負號的 tinyint 運算式會提升至 smallint 結果。
範例
以下範例使用 Orders 資料表說明正負一元運算子的運算方式。對負值加上正一元運算子時,傳回的值為負 (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'
-- 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'.
SELECT -(DATEPART(day, Order Date) - DATEPART(day, Shipped Date))
FROM Orders
WHERE OrderID = '10248'
-- With the negative unary operator, the value returned is '12'.