NOT – SQL Server Syntax Example: NOT – T-SQL Example
NOT – SQL Server Syntax Example: NOT – T-SQL Example
Purpose: – Illustrates the SQL Server syntax for the NOT.
SYNTAX:
SELECT [ ALL | DISTINCT ]
[TOP ( expression ) [PERCENT] [ WITH TIES ] ]
[ INTO new_table ]
[ FROM { table_source } [ ,…n ] ]
[ WHERE [ NOT ] boolean_expression
[ GROUP BY ]
[ HAVING search_condition ]
[ ORDER BY order_expression [ ASC | DESC ]
PURPOSE:
NOT reverses the value of the boolean expression
Code Sample for NOT:
/* NOT example from http://idealprogrammer.com PURPOSE: NOT reverses the value of a boolean expression SYNTAX: [ NOT ] boolean_expression SELECT [ ALL | DISTINCT ] [TOP ( expression ) [PERCENT] [ WITH TIES ] ] column_list, ISNULL(check_expression, replacement_value) [ INTO new_table ] [ FROM { table_source } [ ,...n ] ] [ WHERE [ NOT ] boolean_expression] [ GROUP BY ] [ HAVING search_condition ] [ ORDER BY order_expression [ ASC | DESC ] ] */ CREATE TABLE people( ID int, firstname varchar (20), lastname varchar (20), statecode varchar (2), alive bit, height int ) GO INSERT INTO people (ID, firstname, lastname, statecode, alive, height) VALUES (1, 'Paul', 'Revere', 'AL', 0, 74) GO INSERT INTO people (ID, firstname, lastname, statecode, alive, height) VALUES (2, 'Pat', 'Lennon', 'NY', 0, 69) GO INSERT INTO people (ID, firstname, lastname, statecode, alive, height) VALUES (3, 'Peter', 'Martin', 'NY', 1, 75) GO INSERT INTO people (ID, firstname, lastname, statecode, alive, height) VALUES (4, 'George', 'Washington', 'VA', 0, 75) GO -- Select entire table SELECT 'Entire Table', * FROM people -- 1. Example of using NOT with = (notice NOT preceeds entire expression) SELECT 'Example #1' as Example, firstname, lastname, statecode FROM people p WHERE NOT statecode = 'NY' GO DROP TABLE people; GO |