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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.