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.

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

  1. The expression whose value NOT NULL is returned is TRUE
  2. 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 dan hba 
(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

4 ★ | 1 Vote