Not operator negates a boolean input. The use of NOT negates an expression.
Syntax of NOT Operator
:
[ NOT ] boolean_expression
boolean_expression is valid boolean expression in sql server.
Return type of Not operator is Boolean.
Not reverses the value of any boolean expression.
Below table shows the
truth table of NOT operator.
| NOT |
TRUE | FALSE |
FALSE | TRUE |
UNKNOWN | UNKNOWN |
Examples of NOT Operator :
Example 1 : Using NOT operator in where clause
SELECT ProductName,UnitPrice
FROM Products
WHERE NOT ProductName LIKE 'a%'
Output
ProductName UnitPrice
Chai 18.00
Chang 19.00
Chef
Anton's Cajun Seasoning 22.00
Chef
Anton's Gumbo Mix 21.35
Grandma's
Boysenberry Spread 25.00
Uncle
Bob's Organic Dried Pears 30.00
Northwoods
Cranberry Sauce 40.00
Above query returns product name not starting with character ‘a’,
as expression is negated by NOT operator.