SQL IS NOT NULL

The SQL IS NOT NULL is used to find whether the specified expression is NULL or not, and if it is not NULL, then TRUE will be returned. Otherwise, it returns FALSE. It is always advisable to use SQL Server IS NOT NULL to look for NULL values. The syntax behind the IS NOT NULL is

-- SQL Server IS NOT NULL Syntax
SELECT Column_Names 
FROM Table
WHERE Expression IS NOT NULL

SQL IS NOT NULL Example

The following screenshot will show you the data inside the table.

SQL IS NOT NULL Example 1

In this example, we will use IS NOT NULL to SELECT and return all the customer records from [TenCustomers] table, whose Last Name is NOT NULL value

SELECT [CustomerKey]
      ,[FirstName]
      ,[LastName]
      ,[EmailAddress]
      ,[YearlyIncome]
      ,[EnglishOccupation]
      ,[AddressLine1]
      ,[Phone]
  FROM [TenCustomers]
  WHERE [LastName] IS NOT NULL
SQL IS NOT NULL Example 2

IS NOT NULL Function 2

It is another example of the SQL Server IS NOT NULL function. Here, we are using the [Emp] table, and the data inside this SQL Server table is

SQL IS NOT NULL Example 5

The following IS NOT NULL query returns all the employee records, whose Office Phone numbers are NOT NULL values

SELECT [Id]
      ,[Name]
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Office Phone]
      ,[Mobile]
      ,[Home Phone]
  FROM [SQL Tutorial].[dbo].[Emp]
  WHERE [Office Phone] IS NOT NULL
SQL IS NOT NULL Example 3

The below IS NOT NULL code Selects all the records whose Office numbers, or Mobile numbers are NOT NULL values

-- SQL Server IS NOT NULL example
SELECT [Id]
      ,[Name]
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Office Phone]
      ,[Mobile]
      ,[Home Phone]
  FROM [SQL Tutorial].[dbo].[Emp]
  WHERE [Office Phone] IS NOT NULL OR 
	[Mobile] IS NOT NULL
SQL IS NOT NULL Example 4