SQL Server IS NOT NULL Condition (Operator)

SQL Server IS NOT NULL condition is used to test for a NOT NULL value.

Syntax:

expression IS NOT NULL  

Parameter explanation

expression: It specifies the value to test where it is NOT NULL value.

Note: If the expression is NOT a NULL value, the condition evaluates to TRUE. If it is a NULL value, the condition evaluates to FALSE.

IS NOT NULL operator with SELECT Statement

Example:

Retrieve all employees from the table “Employees” where salary is NOT NULL value.

SELECT *  

FROM [javatpoint].[dbo].[Employees]  

WHERE salary IS NOT NULL;

Output:

SQL Not null 1

IS NOT NULL operator with INSERT Statement

Example:

INSERT INTO [javatpoint].[dbo].[Employees]  

(id, name, salary)  

SELECT id, name, salary  

FROM [javatpoint].[dbo].[Employee2]  

WHERE name IS NOT NULL;

Output:

SQL Not null 2

IS NOT NULL operator with UPDATE Statement

Update the employees of “Employees” table and set the name “Active” where name is not null.

Example:

UPDATE [javatpoint].[dbo].[Employees]  

SET name = 'Active'  

WHERE name IS NOT NULL;

Output:

SQL Not null 3

Verify the example:

SQL Not null 4

IS NOT NULL operator with DELETE Statement

Update the employees of “Employees” table where name is not null.

DELETE  

FROM [javatpoint].[dbo].[Employees]  

WHERE name IS NOT NULL;

Output:

SQL Not null 5

Verify the example:

SQL Not null 6

You can see that all employees are deleted from the table “Employees” where name is NOT NULL.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *