NOT – SQL Server Syntax Example: NOT – T-SQL Example
3-Minute Video Tour of LearnVisualStudio.NET by Bob Tabor
Premium (Not Free) Video Tutorials
Free Video Tutorials & Free Tools
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:
| T-SQL | | | | ? |
/* 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 |
Sample Output for NOT Example
Related posts:
- LIKE – SQL Server Syntax Example: LIKE – T-SQL Example LIKE - SQL Server Syntax Example: LIKE - T-SQL Example...
- IS NULL – SQL Server Syntax Example: IS NULL – T-SQL Example IS NULL - SQL Server Syntax Example: IS NULL -...
- IN – SQL Server Syntax Example: IN – T-SQL Example IN - SQL Server Syntax Example: IN - T-SQL Example...
- ISNULL – SQL Server Syntax Example: ISNULL – T-SQL Example ISNULL - SQL Server Syntax Example: ISNULL - T-SQL Example...
- DISTINCT – SQL Server Syntax Example: DISTINCT – T-SQL Example DISTINCT - SQL Server Syntax Example: DISTINCT - T-SQL Example...
Related posts brought to you by Yet Another Related Posts Plugin.
