NOT (Transact-SQL)NOT (Transact-SQL)

适用对象:是SQL Server 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 是并行数据仓库 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) yesParallel Data Warehouse

对布尔型输入取反。Negates a Boolean input.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

[ NOT ] boolean_expression  

参数Arguments

boolean_expressionboolean_expression
任何有效的布尔表达式Is any valid Boolean expression.

结果类型Result Types

布尔值Boolean

结果值Result Value

NOT 反转任何布尔表达式的值。NOT reverses the value of any Boolean expression.

备注Remarks

使用 NOT 对表达式取反。Using NOT negates an expression.

下表显示使用 NOT 运算符比较 TRUE 和 FALSE 值的结果。The following table shows the results of comparing TRUE and FALSE values using the NOT operator.

NOTNOT
TRUETRUE FALSEFALSE
FALSEFALSE TRUETRUE
UNKNOWN UNKNOWN UNKNOWNUNKNOWN

示例Examples

以下示例查找标准价格不超过 400 美元的所有银色自行车。The following example finds all Silver colored bicycles that do not have a standard price over $400.

-- Uses AdventureWorks  
  
SELECT ProductID, Name, Color, StandardCost  
FROM Production.Product  
WHERE ProductNumber LIKE 'BK-%' AND Color = 'Silver' AND NOT StandardCost > 400;  
GO  

下面是结果集:Here is the result set.

ProductID   Name                     Color         StandardCost
---------   -------------------      ------      ------------
984         Mountain-500 Silver, 40  Silver        308.2179
985         Mountain-500 Silver, 42  Silver        308.2179
986         Mountain-500 Silver, 44  Silver        308.2179
987         Mountain-500 Silver, 48  Silver        308.2179
988         Mountain-500 Silver, 52  Silver        308.2179
(6 row(s) affected)

示例:Azure Synapse Analytics (SQL DW)Azure Synapse Analytics (SQL DW)并行数据仓库Parallel Data WarehouseExamples: Azure Synapse Analytics (SQL DW)Azure Synapse Analytics (SQL DW) and 并行数据仓库Parallel Data Warehouse

以下示例将结果限制为 SalesOrderNumber,以 SO6 开头,ProductKeys 大于或等于 400。The following example restricts results to SalesOrderNumber to values starting with SO6 and ProductKeys greater than or equal to 400.

-- Uses AdventureWorks  
  
SELECT ProductKey, CustomerKey, OrderDateKey, ShipDateKey  
FROM FactInternetSales  
WHERE SalesOrderNumber LIKE 'SO6%' AND NOT ProductKey < 400;  

另请参阅See Also

表达式 (Transact-SQL) Expressions (Transact-SQL)
内置函数 (Transact-SQL) Built-in Functions (Transact-SQL)
运算符 (Transact-SQL) Operators (Transact-SQL)
SELECT (Transact-SQL) SELECT (Transact-SQL)
WHERE (Transact-SQL)WHERE (Transact-SQL)