IS NOT NULL condition in SQL Server
This SQL Server tutorial shows how to use the IS NOT NULL condition along with specific syntax and examples.
The IS NOT NULL condition in SQL Server is used to check if the value is NOT NULL. A NULL value in a table is a value in an empty field, in other words, a field with no value.
Syntax syntax IS NOT NULL
'expression' IS NOT
NULL
Variable name or variable value
Note
- The expression whose value NOT NULL is returned is TRUE
- The expression whose value NULL is returned is FALSE
For example - SELECT command
Example IS NOT NULL condition in SQL Server SELECT statement.
SELECT *
FROM nhanvien
WHERE ho IS NOT NULL;
This example returns all records from the user table whose employee information field contains no NULL values (not left blank).
Example - INSERT command
INSERT INTO danhba
(danhba_id, ho, ten)
SELECT nhanvien_id, ho, ten
FROM nhanvien
WHERE ho IS NOT N
ULL;
This command will insert the record into the namba table if the employee's last name in the table is not NULL.
Example - UPDATE command
UPDATE nhanvien
SET tinhtrang = 'Active'
WHERE ho IS NOT NULL;
The records in the table that have them are not NULL values will be updated.
Example - DELETE command
DELETE FROM nhanvien
WHERE tinhtrang IS NOT NULL;
In this example, all records from the table have a 'status' information field that does not contain a NULL value that will be deleted.
Previous article: IS NULL condition in SQL Server
Next article: Condition LIKE in SQL Server
You should read it
May be interested
- Condition LIKE in SQL Serverthe like condition in sql server (transact-sql) allows the use of wildcards in the where clause.
- Conditions NOT in SQL Serverthe not condition in sql server (transact-server) is also called the not operator, which is used to negate conditions in select, insert, update, and delete statements.
- ALIAS in SQL Serveraliases in sql server is used to create temporary names (called aliases) for columns or tables.
- JOIN in SQL Serverjoin is used to retrieve data from multiple tables, occurring when two or more tables are connected together in an sql statement.
- BETWEEN conditions in SQL Serverin sql server (transact-sql), between conditions are used to retrieve data in a range.
- UPDATE command in SQL Serverin sql server (transact-sql) the update command is used to update the existing records on a table in a sql server database.