Skip to content

Latest commit

 

History

History
107 lines (83 loc) · 3.57 KB

File metadata and controls

107 lines (83 loc) · 3.57 KB
description NOT (Transact-SQL)
title NOT (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 03/15/2017
ms.prod sql
ms.prod_service database-engine, sql-database, sql-data-warehouse, pdw
ms.reviewer
ms.technology t-sql
ms.topic reference
f1_keywords
NOT_TSQL
NOT
dev_langs
TSQL
helpviewer_keywords
negating Boolean input
NOT operator [Transact-SQL]
expressions [SQL Server], negating
reversing Boolean expression values
ms.assetid dc07cc35-20f1-46e6-9995-2938390dc19a
author cawrites
ms.author chadam
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

NOT (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw]

Negates a Boolean input.

Topic link icon Transact-SQL Syntax Conventions

Syntax

[ NOT ] boolean_expression  

[!INCLUDEsql-server-tsql-previous-offline-documentation]

Arguments

boolean_expression
Is any valid Boolean expression.

Result Types

Boolean

Result Value

NOT reverses the value of any Boolean expression.

Remarks

Using NOT negates an expression.

The following table shows the results of comparing TRUE and FALSE values using the NOT operator.

NOT
TRUE FALSE
FALSE TRUE
UNKNOWN UNKNOWN

Examples

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  

[!INCLUDEssResult]

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)

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

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

Expressions (Transact-SQL)
Built-in Functions (Transact-SQL)
Operators (Transact-SQL)
SELECT (Transact-SQL)
WHERE (Transact-SQL)