python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
case in sql server 2008 r2

SQL IS NULL and NOT NULL Clause

“WHERE IS NULL, IS NOT NULL or NO WHERE clause depending on SQL Server parameter value”?
1.      Where IS NULL?
2.      Where IS NOT NULL?
3.      Where ANY VALUE (NULL AND NOT NULL)?

A “NULL” is a special value that signifies “no value” and comparing a column to NULL using the (=) operator is undefined. Instead use WHERE IS NULL or WHERE IS NOT NULL.


Syntax:- 
-- WITH IS NULL
SELECT ColumnName FROM TableName
 WHERE ColumnName IS NULL

-- WITH IS NOT NULL
SELECT ColumnName FROM TableName
 WHERE ColumnName IS NOT NULL

Examples:-
--SELECT ALL COUNTRIES 
SELECT * FROM Countries

Result:-
Id CountryName CountryCode
-----------------------------------
1 India          IN
2 Nepal          NP
3 USA          US
4 Rasia          NULL
5 Australia  AUS

Query With IS NULL:-
-- SELECT IS NULL
SELECT ID, CountryName, CountryCode 
 FROM Countries
WHERE CountryCode IS NULL

Result:-
ID CountryName CountryCode
-----------------------------------
4 Rasia         NULL

Query with IS NOT NULL:-
-- SELECT IS NOT NULL
SELECT ID, CountryName, CountryCode 
 FROM Countries
WHERE CountryCode IS NOT NULL

Result:-
ID CountryName CountryCode
-----------------------------------
1 India         IN
2 Nepal         NP
3 USA         US
5 Australia AUS

Stayed Informed SQL Server Query and Examples

I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions