EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials SQL Tutorial ISNULL SQL Server
 

ISNULL SQL Server

Roja Metla
Article byRoja Metla
EDUCBA
Reviewed byRavi Rathore

Updated March 13, 2023

ISNULL SQL Server

 

 

Introduction to ISNULL SQL Server

ISNULL () function is used when you want a specific value that needs to be returned if the expression value is NULL. If the expression value will be returned then the expression value is not null. In this topic, we are going to learn about ISNULL SQL Server.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

We get two arguments in the ISNULL () function. One is the expression and the other is value. Based on the expression it decides whether to return the expression value (if expression value is not null) or defined value (if expression value is null).

Now in this session let us see the usage of ISNULL () function and find the example of the ISNULL () function.

Syntax: –

Below is the syntax for the ISNULL () function: –

isnull(<expression>,<value>); /* - - - -  ISNULL () SYNTAX - - - */

Based on the expression it decides whether to return the expression value (if expression value is not null) or defined value (if expression value is null).

How ISNULL in SQL Server Works?

Now let us see the usage of ISNULL () function in the SQL server.

select isnull('Hello','replace value of the NULL')AS "IS NULL";

Output:

isnull sql server output 1

Here the expression value is not NULL because of which the actual values is returned.

select isnull(NULL,'replace value of the NULL')AS "IS NULL";

Output:

isnull sql server output 2

Here the expression value is NULL because of which the replacement values is returned.

Now let us apply the ISNULL () function in a table.

Table creation: –

CREATE TABLE test_NULL
(
SERIAL_NO INT
,NAME VARCHAR(20)
,LOCATION VARCHAR(20)
, AGE INT
, OCCUPATION VARCHAR(20)
)

Now let us insert data into the table: –

INSERT INTO TEST_NULL VALUES (1,'Rose','USA', 24,'Software Engineer');
INSERT INTO TEST_NULL VALUES (2,'Rahul','India',NULL,'Artist');
INSERT INTO TEST_NULL VALUES (3,'Will','Denmark', 24,'Software Engineer');
INSERT INTO TEST_NULL VALUES (4,'Ben','Polland',NULL,'Actress');
INSERT INTO TEST_NULL VALUES (5,'Sian','FIA', 24,'Writer');
INSERT INTO TEST_NULL VALUES (6,'Rodger','Norway', 24,'Software Engineer');
INSERT INTO TEST_NULL VALUES (7,'Harry','USA',NULL,'Artist');
INSERT INTO TEST_NULL VALUES (8,'Kiyana','USA', 24,'Software Engineer');
INSERT INTO TEST_NULL VALUES (9,'Pradhush','USA', 24,'Writer');
INSERT INTO TEST_NULL VALUES (10,'Dawson','USA',NULL,'Painter');

Let us select the table and below output rows are display: –

select * from TEST_NULL;

isnull sql server output 3

Here in the above output, you could see that the age of the people is NULL for a few rows. Instead of entering the value of NULL, we can insert a default value as 99 if the age is not mentioned with the below statement.

SELECT *,ISNULL(AGE, 99)AS "FORMATTED_AGE" FROM TEST_NULL;

Output:

isnull sql server output 4

The value of NULL is replaced with the default value 99.

If you want to update the existing table with the same values uses the below statement: –

UPDATE TEST_NULL
SET AGE =ISNULL(AGE, 99);
SELECT*FROM TEST_NULL;

Output:

output 5

We can use the function in the insert statement as well as below: –

INSERT INTO TEST_NULL VALUES (11,'Sony','Korea',ISNULL(NULL, 99),'Painter');

Quickly let us select the mentioned row. 99 value will be saved instead of NULL.

SELECT * FROM TEST_NULL WHERE SERIAL_NO = 11;

The screenshot is for the same: –

output 6

Examples of ISNULL SQL Server

Below are the examples mentioned:

Example #1

Now let us see the usage of ISNULL () function in the SQL server.

Code:

select isnull('234567','replace value of the NULL')AS "IS NULL";

Output:

output 7

Example #2

Here in the above expression value is not NULL because of which the actual values is returned.

Code:

select isnull(NULL,'replace value of the NULL')AS "IS NULL";

Output:

output 8

Example #3

Here in the above expression value is NULL because of which the replacement values is returned.

Code:

select isnull('ROSE','Dawson')AS "IS NULL";

Output:

output 9

Example #4

Here in the above expression value is not NULL because of which the actual values is returned.

Code:

select isnull(NULL,'Rose')AS "IS NULL";

Output:

output 10

Here in the above expression value is NULL because of which the replacement values is returned.

Conclusion

ISNULL () function is used when you want a specific value that needs to be returned if the expression value is NULL. If the expression value is not null, then the expression value will be returned.

We get two arguments in the ISNULL () function. One is the expression and the other is value. Based on the expression it decides whether to return the expression value (if expression value is not null) or defined value (if expression value is null).

Recommended Articles

We hope that this EDUCBA information on “ISNULL SQL Server” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. SQL IN Operator
  2. SQL INSTR()
  3. SQL Server Substring
  4. SQL Server Data Types

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW