Home ยป SQL IS NULL

SQL IS NULL

The IS NULL is used in SQL to find a NULL value. It returns TRUE if a NULL value is found, otherwise it returns FALSE.



SYNTAX

SELECT col1, col2, ..
FROM Table
WHERE Expression IS NULL

expression is the expression to check for a NULL value.

Lets take a look at IS NULL in SQL , first we will create a sample table and insert some records into table.

CREATE TABLE dbo.EmpData
( EmpId INT,
Name VARCHAR(100),
Code VARCHAR(10),
Department VARCHAR(50),
Age INT
)

INSERT INTO dbo.EmpData
(EmpId, Name, Code, Department, Age)
VALUES
(1, 'Ajit Singh', null, 'CS', 35),
(2, 'Mohit Sharma', 'EmXTY', null, 31),
(3, 'Sujit Kumar', 'fMFSf', 'ES', 39),
(4, 'Mukul Aggarwal', 'Hrtms', null, 41),
(5, 'Sumit viyas', null, 'CS', 32),
(6, 'Sanjay Rawat', null, 'ES', 64),
(7, 'Gaurav Kumar', 'Ryrgt', null, 43),
(8, 'Amit kumar', null, null, 28)

Now we have a table named EmpData as shown below.

SELECT * FROM dbo.EmpData

Lets see how to use IS NULL to find the null values in table.



As you can see the output of table EmpData in above screenshot, there are few null values in Code and Department columns.

Lets select the employee records from table EmpData, whose Code is null.

SELECT * FROM dbo.EmpData
WHERE Code IS NULL

You can see, it returns only those records whose code values is null.

Lets see one more example, this time we will select all employees from EmpData table whose Code values, or Department name is null.

SELECT * FROM dbo.EmpData
WHERE Code IS NULL OR Department IS NULL

You can see, it returns only those employee’s records whose either code values is null or department name is null.

Lets select all employees from EmpData table whose Code values, and Department name is null.

SELECT * FROM dbo.EmpData
WHERE Code IS NULL and Department IS NULL

You can see, it returns only those employees whose code value and department name is null.



Also Read..

SQL IS NOT NULL

SQL Server NOT NULL Constraint

SQL Basics TutorialSQL Advance TutorialSSRSInterview Q & A
SQL Create tableSQL Server Stored ProcedureCreate a New SSRS Project List Of SQL Server basics to Advance Level Interview Q & A
SQL ALTER TABLESQL Server MergeCreate a Shared Data Source in SSRSSQL Server Question & Answer Quiz
SQL DropSQL Server PivotCreate a SSRS Tabular Report / Detail Report
..... More.... More....More
Power BI TutorialAzure TutorialPython TutorialSQL Server Tips & Tricks
Download and Install Power BI DesktopCreate an Azure storage accountLearn Python & ML Step by stepEnable Dark theme in SQL Server Management studio
Connect Power BI to SQL ServerUpload files to Azure storage containerSQL Server Template Explorer
Create Report ToolTip Pages in Power BICreate Azure SQL Database ServerDisplaying line numbers in Query Editor Window
....More....More....More

 410 total views,  1 views today

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.