Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

SQL Server - Handle NULL value in Where Clause

Article:
Viewed:  915 
Posted On:  30/04/2015 20:17:24 
How to select records from a table if it has NULL value in a column? 

 

Sometime you have to select values from your SQL Server table if record has null value or not. For example I have below table in design mode and with records.

1.png

Image 1.

2.png

Image 2.

Now Write Query to Select All records:

SELECT * FROM EMPLOYEE

3.png

Image 3.

Now if you want to fetch those records who have EXPERIENCE as null. You will want to write your query like below:

SELECT * FROM EMPLOYEE WHERE EXPERIENCE = NULL
 

SELECT * FROM EMPLOYEE WHERE EXPERIENCE = 0
 

SELECT * FROM EMPLOYEE WHERE EXPERIENCE < 1

4.png

Image 4.

Now write your query like below:

SELECT * FROM EMPLOYEE WHERE EXPERIENCE IS NULL

 

5.png

Image 5.

SELECT * FROM EMPLOYEE WHERE ISNULL(EXPERIENCE,0)=0

 

6.png

Image 6.

Now query to select All records where Experience is Not Null

SELECT * FROM EMPLOYEE WHERE EXPERIENCE IS NOT NULL

7.png

Image 7.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us