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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^